diff options
| author | Henry <mail@henrygressmann.de> | 2026-04-19 17:48:32 +0200 |
|---|---|---|
| committer | Henry <mail@henrygressmann.de> | 2026-04-19 17:49:59 +0200 |
| commit | e667ae4554e816b4081d874fc3564b07c28dbec6 (patch) | |
| tree | 534aa3b8b40eb42e77e7f4979d6fc0f3ad320c9e /examples/funcref_callbacks.rs | |
| parent | 684d5a04a928ea4132d0c5e61bb4086fac9feb22 (diff) | |
feat: simplify module api
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'examples/funcref_callbacks.rs')
| -rw-r--r-- | examples/funcref_callbacks.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/examples/funcref_callbacks.rs b/examples/funcref_callbacks.rs index f517e30..8ff9b49 100644 --- a/examples/funcref_callbacks.rs +++ b/examples/funcref_callbacks.rs @@ -1,5 +1,5 @@ use eyre::Result; -use tinywasm::{FuncContext, HostFunction, Imports, Module, Store, types::FuncRef}; +use tinywasm::{FuncContext, HostFunction, Imports, ModuleInstance, Store, types::FuncRef}; const LHS: i32 = 5; const RHS: i32 = 3; @@ -47,7 +47,7 @@ fn run_passed_funcref_example() -> Result<()> { "#; let wasm = wat::parse_str(WASM).expect("failed to parse wat"); - let module = Module::parse_bytes(&wasm)?; + let module = tinywasm::parse_bytes(&wasm)?; let mut store = Store::default(); let mul = HostFunction::from(&mut store, |_, (lhs, rhs): (i32, i32)| -> tinywasm::Result<i32> { Ok(lhs * rhs) }); @@ -62,7 +62,7 @@ fn run_passed_funcref_example() -> Result<()> { let mut imports = Imports::new(); imports.define("host", "call_this", call_this).define("host", "mul", mul); - let instance = module.instantiate(&mut store, Some(imports))?; + let instance = ModuleInstance::instantiate(&mut store, &module, Some(imports))?; let caller = instance.func::<(), ()>(&store, "tell_host_to_call")?; caller.call(&mut store, ())?; @@ -103,14 +103,14 @@ fn run_returned_funcref_example() -> Result<()> { "#; let wasm = wat::parse_str(WASM).expect("failed to parse wat"); - let module = Module::parse_bytes(&wasm)?; + let module = tinywasm::parse_bytes(&wasm)?; let mut store = Store::default(); let mut imports = Imports::new(); let mul = HostFunction::from(&mut store, |_, (lhs, rhs): (i32, i32)| -> tinywasm::Result<i32> { Ok(lhs * rhs) }); imports.define("host", "mul", mul); - let instance = module.instantiate(&mut store, Some(imports))?; + let instance = ModuleInstance::instantiate(&mut store, &module, Some(imports))?; let (add_ref, sub_ref, mul_ref) = { let get_funcrefs = instance.func::<(), (FuncRef, FuncRef, FuncRef)>(&store, "what_should_host_call")?; get_funcrefs.call(&mut store, ())? |
