I see that I can provide a list of Externs generated from Funcs, but how do I specify the name of each function? Otherwise, how will the wasm module know what to call? I'm looking for the equivalent of this https://docs.wasmer.io/integrations/examples/host-functions#declaring-functions-and-imports
If you're using an API like Instance::new
which takes the externs as &[Extern]
, they're linked to the module's imports in the order that they appear in the module.
Oh. I don't think I can control that - the module is generated from Rust, which has a bunch of scattered extern "C" functions all over the place.
For a higher-level API that links things by name see the Linker
API
Oh nice, ty!
https://docs.wasmtime.dev/examples-rust-linking.html has an example using that API, in case it helps.
Yep, figured it out, ty!
Do you know how I can wrap this function? I don't think it likes that it borrows Bay.
fn setup_linker(engine: &Engine, bay: &Bay) -> Result<Linker<StoreData>, Box<dyn Error>> {
let mut linker = Linker::new(engine);
linker.func_wrap(
"host",
"__move_towards",
|mut caller: Caller<'_, StoreData>| match caller.data().bot_action {
None => {
let action_result = bay.can_move_towards()?;
caller.data_mut().bot_action = Some(BotAction::MoveTowards);
Ok(action_result)
}
_ => Err(ActionError::AlreadyActed),
},
)?;
Ok(linker)
}
Trying to store &'a Bay in my StoreData didn't work either :/
Nvm, was an issue with my return type
JMS has marked this topic as resolved.
Last updated: Dec 23 2024 at 13:07 UTC