MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / host_fn

Function host_fn

examples/wasm-rust.rs:128–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

126}
127
128fn host_fn() -> Result<()> {
129 let module = tinywasm::parse_file("./examples/rust/out/host_fn.opt.wasm")?;
130 let mut store = Store::default();
131
132 let bar = HostFunction::from(&mut store, |_: FuncContext<'_>, (left, right): (i64, i32)| {
133 assert_eq!(left, 1);
134 assert_eq!(right, 2);
135 Ok(left as i32 + right)
136 });
137
138 let mut imports = Imports::new();
139 imports.define("env", "bar", bar);
140
141 let instance = ModuleInstance::instantiate(&mut store, &module, Some(imports))?;
142 let host_fn = instance.func::<(), i32>(&store, "foo")?;
143 assert_eq!(host_fn.call(&mut store, ())?, 3);
144 Ok(())
145}
146
147fn printi32() -> Result<()> {
148 let module = tinywasm::parse_file("./examples/rust/out/print.opt.wasm")?;

Callers 1

mainFunction · 0.85

Calls 2

parse_fileFunction · 0.85
defineMethod · 0.80

Tested by

no test coverage detected