Skip to content

How to handle bound (win.binding) functions with a union signature #103

@elverskog

Description

@elverskog

Took a bit to figure out an error related to a bound (win.binding) function, I created, not returning void.
I submitted a PR here to improve the error visibility:
#102

But what I am asking here is, what it the best way to deal with a bound function that needs to have a !void signature, due to there being a try in the function.

Should I create an intermediate function (that always returns void) to call the function with the try in it?

Here is the code that breaks:

Bind the webUI event receiver to my parser function (in main.zig)
_ = try win.binding("send_project_from_webui", proj.get_project_from_webui);

Event receiver function

pub fn send_project_from_webui(e: *webui.Event) void {
    const json = e.getString();
    _ = json;
}

Parser function

pub fn get_project_from_webui(json: []const u8) !void {
  
    const Setup = struct {
      proj_name: []const u8,
      proj_bpm: u16,
      created: u32,
      last_saved: u32
    };

    const allocator = std.heap.page_allocator;

    const json_tree = try std.json.parseFromSlice(Setup, allocator, json, .{});
    defer json_tree.deinit();

    const json_val = try json_tree.value;
    const proj_name = json_val.proj_name;
    
    std.debug.print("\n\nPROJ_NAME{s}\n\n", .{proj_name});
  
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions