Skip to content

Func call only works for comptime values. #2

@somethingelseentirely

Description

@somethingelseentirely

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:

wasm-zig/src/main.zig

Lines 170 to 186 in 8f9a0d1

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) + "'"),
};
}

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