Skip to content

Commit f995d7f

Browse files
committed
wasm: implement initFromImports (ExternVec)
1 parent e8f09a7 commit f995d7f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/wasm.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,21 @@ pub const Instance = opaque {
340340
return instance orelse Error.InstanceInit;
341341
}
342342

343+
pub fn initFromImports(store: *Store, module: *Module, imports: *ExternVec) !*Instance {
344+
var trap: ?*Trap = null;
345+
346+
const instance = wasm_instance_new(store, module, imports, &trap);
347+
348+
if (trap) |t| {
349+
defer t.deinit();
350+
// TODO handle trap message
351+
log.err("code unexpectedly trapped", .{});
352+
return Error.InstanceInit;
353+
}
354+
355+
return instance orelse Error.InstanceInit;
356+
}
357+
343358
/// Returns an export func by its name if found
344359
/// Asserts the export is of type `Func`
345360
/// The returned `Func` is a copy and must be freed by the caller

0 commit comments

Comments
 (0)