It looks like Func.call
can only be called with comptime
known values.
I'm not sure if this was missed because all the examples only use literals, or if the semantic of zig has changed recently.
Not being able to call functions with dynamic values makes calling them rather moot, so I'll see what I can do to fix this 😅
Code in question is here:
|
pub fn call(self: *Func, comptime ResultType: type, args: anytype) CallError!ResultType { |
|
if (!comptime trait.isTuple(@TypeOf(args))) |
|
@compileError("Expected 'args' to be a tuple, but found type '" ++ @typeName(@TypeOf(args)) ++ "'"); |
|
|
|
const args_len = args.len; |
|
comptime var wasm_args: [args_len]Value = undefined; |
|
inline for (wasm_args) |*arg, i| { |
|
arg.* = switch (@TypeOf(args[i])) { |
|
i32, u32 => .{ .kind = .i32, .of = .{ .i32 = @intCast(i32, args[i]) } }, |
|
i64, u64 => .{ .kind = .i64, .of = .{ .i64 = @intCast(i64, args[i]) } }, |
|
f32 => .{ .kind = .f32, .of = .{ .f32 = args[i] } }, |
|
f64 => .{ .kind = .f64, .of = .{ .f64 = args[i] } }, |
|
*Func => .{ .kind = .funcref, .of = .{ .ref = args[i] } }, |
|
*Extern => .{ .kind = .anyref, .of = .{ .ref = args[i] } }, |
|
else => |ty| @compileError("Unsupported argument type '" ++ @typeName(ty) + "'"), |
|
}; |
|
} |