so I have the following import in my generated .wast file (disclaimer: I have not written the wasm file myself):
(import "index" "bigDecimal.fromString" (func $fimport$1 (param i32) (result i32)))
and I need to write up the host import function in Rust. I cannot use &str in Rust but also the import requires an i32. I'm guessing I need to pass a pointer to a string, defined in Rust? Can anyone point me to the right direction? Some example of that being done in wasmtime?
let from_string = Func::wrap(&store, |a: i32| {
println!("a={}", a);
});
Thanks a ton in advance!
You are right, the parameter
a
is a pointer to the string inside of the Wasm modules memory. You can access this viawasmtime::Memory::data_ptr(...)
function. To get the memory from the caller you can add a parameter of typewasmtime::Caller
to your closure. This parameter must not be in your wasm modules function signature but only in the host functions signature.I hope this short example will help: