summaryrefslogtreecommitdiff
path: root/examples/reentrance.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-10-31 11:10:49 -0400
committerMica White <botahamec@outlook.com>2026-10-31 11:10:49 -0400
commit264ea48cc8c6dd9c3c9e0fe1a559252863fc9962 (patch)
tree84a4a58de14442f4fcfa06bd0d82480508f82759 /examples/reentrance.rs
parent7877eca4e8be283e7c51168ee3a3b05d9000f39c (diff)
parentb45a98a85c776d956a797773acd2f198c06b40ed (diff)
Merge branch 'main' into bota-tortuise
Diffstat (limited to 'examples/reentrance.rs')
-rw-r--r--examples/reentrance.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/examples/reentrance.rs b/examples/reentrance.rs
index 432fac7..cf57891 100644
--- a/examples/reentrance.rs
+++ b/examples/reentrance.rs
@@ -1,4 +1,4 @@
-use eyre::Result;
+use anyhow::Result;
use tinywasm::{FuncContext, HostFunction, Imports, ModuleInstance, Store};
const WASM: &str = r#"
@@ -22,11 +22,12 @@ fn main() -> Result<()> {
let module = tinywasm::parse_bytes(&wasm)?;
let mut store = Store::default();
- let call_add_twice = HostFunction::from(&mut store, |mut ctx: FuncContext<'_>, value: i32| {
+ let call_add_twice = HostFunction::from(|mut ctx: FuncContext<'_>, value: i32| {
+ // FuncContext exposes the active module and its Store to the callback.
let add_one = ctx.module().func::<i32, i32>(ctx.store(), "add_one")?;
- // Use ctx.call for reentrant calls from host functions. Function::call
- // starts a root invocation and cannot preserve the active call stacks.
+ // Use ctx.call while a host callback has an active Wasm invocation.
+ // Function::call only starts top-level invocations.
let value = ctx.call(&add_one, value)?;
ctx.call(&add_one, value)
});
@@ -34,7 +35,7 @@ fn main() -> Result<()> {
let mut imports = Imports::new();
imports.define("host", "call_add_twice", call_add_twice);
- let instance = ModuleInstance::instantiate(&mut store, &module, Some(imports))?;
+ let instance = ModuleInstance::instantiate(&mut store, &module, Some(&imports))?;
let run = instance.func::<i32, i32>(&store, "run")?;
assert_eq!(run.call(&mut store, 40)?, 52);