Skip to content

Commit

Permalink
Merge pull request #3 from yelsharawy/main
Browse files Browse the repository at this point in the history
Fixed type checking and `sliceTo` calls in `bind`
  • Loading branch information
thechampagne authored May 24, 2024
2 parents 4f4208e + 9e1e97d commit 3bc017e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/webview.zig
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ pub const WebView = struct {

pub fn bind(self: Self, name: [:0]const u8, func: anytype, arg: ?*anyopaque) void {
const T = @TypeOf(func);
if (T != BindCallback and T != fn (WebView, ?*anyopaque) void) {
if (T != BindCallback and T != fn ([:0]const u8, [:0]const u8, ?*anyopaque) void) {
@compileError(fmt.comptimePrint("expected type 'fn ([:0]const u8, [:0]const u8, ?*anyopaque) void' or '*const fn ([:0]const u8, [:0]const u8, ?*anyopaque) void', found '{any}'",
.{T}));
}
const callback = struct {
var callback: BindCallback = undefined;
fn function(seq: [*c]const u8, req: [*c]const u8, ctx: ?*anyopaque) callconv(.C) void {
if (T == BindCallback) {
callback(mem.sliceTo(seq), mem.sliceTo(req), ctx);
callback(mem.sliceTo(seq, 0), mem.sliceTo(req, 0), ctx);
} else {
@call(.always_inline, func, .{mem.sliceTo(seq), mem.sliceTo(req), ctx});
@call(.always_inline, func, .{mem.sliceTo(seq, 0), mem.sliceTo(req, 0), ctx});
}
}
};
Expand Down

0 comments on commit 3bc017e

Please sign in to comment.