~mil/mepo

976a6ea565c33abf7a2ecf5451050bc2158fa0ee — Miles Alan 1 year, 7 months ago 716480f zig-0.10.0
Complete update to zig 0.10.0: optional formatting, const fn ptrs, etc.
5 files changed, 42 insertions(+), 27 deletions(-)

M src/Docs.zig
M src/Mepo.zig
M src/api/_FnTable.zig
M src/api/filedump.zig
M src/util/utilsdl.zig
M src/Docs.zig => src/Docs.zig +8 -2
@@ 210,7 210,10 @@ pub fn generate(allocator: std.mem.Allocator, format: enum{Markdown, Manpage}) !

                var value : []const u8 = "";
                switch(pref.value) {
                    .t =>    { value = try std.fmt.allocPrint(allocator, "{s}", .{pref.value.t}); },
                    .t =>    {
                        const text = if (pref.value.t) |t| t else "";
                        value = try std.fmt.allocPrint(allocator, "{s}", .{text});
                     },
                    .b =>    { 
                        if (pref.value.b) {
                            value = try std.fmt.allocPrint(allocator, "{d}", .{1});


@@ 433,7 436,10 @@ pub fn generate(allocator: std.mem.Allocator, format: enum{Markdown, Manpage}) !
                var value : []const u8 = "";
                
                switch(pref.value) {
                    .t =>    { value = try std.fmt.allocPrint(allocator, "{s}", .{pref.value.t}); },
                    .t =>    { 
                        const text = if (pref.value.t) |t| t else "";
                        value = try std.fmt.allocPrint(allocator, "{s}", .{text});
                    },
                    .b =>    { 
                        if (pref.value.b) {
                            value = try std.fmt.allocPrint(allocator, "{d}", .{1});

M src/Mepo.zig => src/Mepo.zig +26 -19
@@ 314,7 314,12 @@ fn blit_pin(mepo: *@This(), pin: types.Pin, prev_pin: ?types.Pin, pin_group: u8,
        };
        const label_color: u24 = 0x000000;

        const label = if (pin.metadata.get("name")) |name| name else pin.handle;
        const label = lab: {
            if (pin.metadata.get("name")) |name| break :lab name;
            if (pin.handle) |h| break :lab h;
            break :lab "";
        };

        try mepo.blit_multiline_text(
            label_color,
            pin_label_border,


@@ 1067,27 1072,29 @@ pub fn sdl_event_loop(mepo: *@This()) !void {

        // Process SDL events
        if (sdl.SDL_WaitEventTimeout(&e, config.DragThresholdTicks) > 0) {
            pending = switch (e.type) {
                sdl.SDL_FINGERDOWN => event_fingerdown,
                sdl.SDL_FINGERUP => event_fingerup,
                sdl.SDL_KEYUP => event_keyup,
                sdl.SDL_MOUSEBUTTONDOWN => event_mousebuttondown,
                sdl.SDL_MOUSEBUTTONUP => event_mousebuttonup,
                sdl.SDL_MOUSEMOTION => event_mousemotion,
                sdl.SDL_MOUSEWHEEL => event_mousewheel,
                sdl.SDL_MULTIGESTURE => event_multigesture,
                sdl.SDL_TEXTINPUT => event_textinput,
                sdl.SDL_QUIT => event_quit,
                sdl.SDL_WINDOWEVENT => event_windowevent,
            var pending_fn = switch (e.type) {
                sdl.SDL_FINGERDOWN => &event_fingerdown,
                sdl.SDL_FINGERUP => &event_fingerup,
                sdl.SDL_KEYUP => &event_keyup,
                sdl.SDL_MOUSEBUTTONDOWN => &event_mousebuttondown,
                sdl.SDL_MOUSEBUTTONUP => &event_mousebuttonup,
                sdl.SDL_MOUSEMOTION => &event_mousemotion,
                sdl.SDL_MOUSEWHEEL => &event_mousewheel,
                sdl.SDL_MULTIGESTURE => &event_multigesture,
                sdl.SDL_TEXTINPUT => &event_textinput,
                sdl.SDL_QUIT => &event_quit,
                sdl.SDL_WINDOWEVENT => &event_windowevent,
                else => b: {
                    // Async events triggered outside of main thread:
                    // 1) signals & 2) mepolang trigged via shellpipe or STDIN
                    if (e.type == utilsdl.sdl_usereventtype(.Mepolang)) break :b event_mepolangexecution;
                    if (e.type == utilsdl.sdl_usereventtype(.Signal)) break :b event_signal;
                    if (e.type == utilsdl.sdl_usereventtype(.Mepolang)) break :b &event_mepolangexecution;
                    if (e.type == utilsdl.sdl_usereventtype(.Signal)) break :b &event_signal;
                    // Unhandled case
                    break :b event_unhandled;
                    break :b &event_unhandled;
                },
            }(mepo, e);
            };
            
            pending = pending_fn(mepo, e);
        }
    }
}


@@ 1401,7 1408,7 @@ fn setup_sdl_video_and_window(allocator: std.mem.Allocator) !*sdl.SDL_Window {
            defer allocator.free(env_videodriver_z);
            utildbg.log("SDL_VIDEODRIVER env var set to {s}, attempting initialize\n", .{env_videodriver});
            utilsdl.errorcheck(sdl.SDL_VideoInit(&env_videodriver_z[0])) catch |e| {
                utildbg.log("SDL Videodriver {s} failed to initialized: {s}\n", .{ env_videodriver, e });
                utildbg.log("SDL Videodriver {s} failed to initialized: {any}\n", .{ env_videodriver, e });
                break :env_videoinit;
            };
            break :video_init;


@@ 1412,7 1419,7 @@ fn setup_sdl_video_and_window(allocator: std.mem.Allocator) !*sdl.SDL_Window {
        for (prefered_sdl_videodrivers_order) |driver| {
            utildbg.log("SDL Videodriver {s} attempting to initialize\n", .{driver});
            utilsdl.errorcheck(sdl.SDL_VideoInit(&driver[0])) catch |e| {
                utildbg.log("SDL Videodriver {s} failed to initialized: {s}\n", .{ driver, e });
                utildbg.log("SDL Videodriver {s} failed to initialized: {any}\n", .{ driver, e });
                continue;
            };
            break :video_init;

M src/api/_FnTable.zig => src/api/_FnTable.zig +1 -1
@@ 38,7 38,7 @@ pub const fn_specs = &[_]types.MepoFnSpec{
    @import("zoom_relative.zig").spec,
};

pub fn get(comptime get_fn: []const u8) ?types.MepoFnSpec {
pub fn get(get_fn: []const u8) ?types.MepoFnSpec {
    for (fn_specs) |f| {
        if (std.mem.eql(u8, f.name, get_fn)) return f;
    }

M src/api/filedump.zig => src/api/filedump.zig +5 -3
@@ 58,7 58,8 @@ fn filedump(mepo: *Mepo, save_types: []const u8, filepath: []const u8) !void {
            };
            const prefset_statement = statement: {
                if (format_as == .Text) {
                    break :statement try std.fmt.allocPrint(arena.allocator(), "prefset_t {s} [{s}];", .{ pref.name, pref.value.t });
                    const text = if (pref.value.t) |t| t else "";
                    break :statement try std.fmt.allocPrint(arena.allocator(), "prefset_t {s} [{s}];", .{ pref.name, text });
                } else if (format_as == .Number) {
                    break :statement try std.fmt.allocPrint(arena.allocator(), "prefset_n {s} {d:0.04};", .{ pref.name, numerical_val });
                } else if (format_as == .HexText) {


@@ 145,10 146,11 @@ fn filedump(mepo: *Mepo, save_types: []const u8, filepath: []const u8) !void {
        // UI Buttons
        for (mepo.uibuttons.items) |btn| {
            const pins_only_btn: u8 = if (btn.only_visible_when_pin_active) 1 else 0;
            const group_number : i8 = if (btn.group_number) |g| @intCast(i8, g) else -1;
            const statement_button = try std.fmt.allocPrint(
                arena.allocator(),
                "bind_button {d} {d} [{s}] [{s}] [{s}];",
                .{ pins_only_btn, btn.group_number, btn.text, btn.mepolang_click_single, btn.mepolang_click_hold },
                .{ pins_only_btn, group_number, btn.text, btn.mepolang_click_single, btn.mepolang_click_hold },
            );
            try lines.append(statement_button);
        }


@@ 180,7 182,7 @@ fn filedump(mepo: *Mepo, save_types: []const u8, filepath: []const u8) !void {
                    const statement_meta = try std.fmt.allocPrint(
                        arena.allocator(),
                        "pin_meta {d} [{s}] [{s}] [{s}];",
                        .{ pg_i, pin.handle, kv.key_ptr.*, kv.value_ptr.* },
                        .{ pg_i, handle, kv.key_ptr.*, kv.value_ptr.* },
                    );
                    try lines.append(statement_meta);
                }

M src/util/utilsdl.zig => src/util/utilsdl.zig +2 -2
@@ 28,7 28,7 @@ pub fn sdl_push_event_resize() void {
    sdlevent.type = sdl.SDL_WINDOWEVENT;
    sdlevent.window.event = sdl.SDL_WINDOWEVENT_EXPOSED;
    errorcheck(sdl.SDL_PushEvent(&sdlevent)) catch |err| {
        utildbg.log("Error pushing resize event to SDL queue: {s}\n", .{err});
        utildbg.log("Error pushing resize event to SDL queue: {any}\n", .{err});
    };
}



@@ 40,7 40,7 @@ pub fn sdl_push_event_mepolang_execution(mepolang_text: [:0]const u8) void {
    sdlevent.user.data1 = @intToPtr([*c]u8, @ptrToInt(str_ptr));
    sdlevent.user.data2 = null;
    errorcheck(sdl.SDL_PushEvent(&sdlevent)) catch |err| {
        utildbg.log("Error pushing mepolang event to SDL queue: {s}\n", .{err});
        utildbg.log("Error pushing mepolang event to SDL queue: {any}\n", .{err});
    };
}