MCPcopy Create free account
hub / github.com/explodingcamera/tinywasm / run

Function run

examples/rust/src/tinywasm.rs:14–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12}
13
14fn run() -> tinywasm::Result<()> {
15 let module = tinywasm::parse_stream(&include_bytes!("./print.wasm")[..])?;
16 let mut store = tinywasm::Store::default();
17
18 let printi32 = HostFunction::from(&mut store, |_: FuncContext<'_>, v: i32| {
19 unsafe { printi32(v) }
20 Ok(())
21 });
22
23 let mut imports = tinywasm::Imports::new();
24 imports.define("env", "printi32", printi32);
25
26 let instance = ModuleInstance::instantiate(&mut store, &module, Some(imports))?;
27 let add_and_print = instance.func::<(i32, i32), ()>(&store, "add_and_print")?;
28 add_and_print.call(&mut store, (1, 2))?;
29 Ok(())
30}

Callers 1

helloFunction · 0.70

Calls 4

parse_streamFunction · 0.85
printi32Function · 0.85
defineMethod · 0.80
callMethod · 0.80

Tested by

no test coverage detected