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

Function run

examples/rust/src/tinywasm_no_std.rs:27–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25}
26
27fn run() -> tinywasm::Result<()> {
28 let mut store = tinywasm::Store::default();
29 let mut imports = tinywasm::Imports::new();
30
31 let res = tinywasm::parser::Parser::new().parse_module_bytes(include_bytes!("./print.wasm"))?;
32 let twasm = res.serialize_twasm()?;
33 let module = tinywasm::parse_bytes(&twasm)?;
34
35 let printi32 = HostFunction::from(&mut store, |_: FuncContext<'_>, v: i32| {
36 unsafe { printi32(v) }
37 Ok(())
38 });
39
40 imports.define("env", "printi32", printi32);
41 let instance = ModuleInstance::instantiate(&mut store, &module, Some(imports))?;
42 let add_and_print = instance.func::<(i32, i32), ()>(&store, "add_and_print")?;
43 add_and_print.call(&mut store, (1, 2))?;
44 Ok(())
45}

Callers 1

helloFunction · 0.70

Calls 6

parse_bytesFunction · 0.85
printi32Function · 0.85
parse_module_bytesMethod · 0.80
serialize_twasmMethod · 0.80
defineMethod · 0.80
callMethod · 0.80

Tested by

no test coverage detected