()
| 126 | } |
| 127 | |
| 128 | fn 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 | |
| 147 | fn printi32() -> Result<()> { |
| 148 | let module = tinywasm::parse_file("./examples/rust/out/print.opt.wasm")?; |
no test coverage detected