nerdachse opened issue #8943:
Hey there!
Similar to #8670 (which I read), I have a problem with calling multiple functions of a
wasm component
.let info_func = { let mut exports: wasmtime::component::Exports = plugin.exports(&mut store); let mut register = exports .instance("test:guest/info") .expect(&format!("plugin@{path:?} to have info instance")); match register.typed_func::<(), (PluginInfo,)>("info") { Ok(info) => info, Err(e) => { eprintln!("plugin@{path:?} does not have an info function: {e}!"); continue; } } }; let info = info_func.call(&mut store, ()); println!("plugin@{path:?}: {info:?}"); // Scope the borrow of &mut store to limit its lifetime let init_func = { let mut exports: wasmtime::component::Exports = plugin.exports(&mut store); let mut register = exports .instance("test:guest/register") .expect(&format!("plugin@{:?} to have register instance", path)); match register.typed_func::<(), (String,)>("init") { Ok(init) => init, Err(e) => { eprintln!("plugin@{:?} does not have an init function: {}!", path, e); continue; } } }; // Now call the init function after the borrow from exports has ended let result = init_func.call(&mut store, ()).expect("init to be callable"); println!("plugin@{:?} result of init: {:?}", path, result);
gives me:
thread 'main' panicked at src/main.rs:121:53:
init to be callable: wasm trap: cannot enter component instanceNow I understand the problem but in #8670 it was said that there could be another solution for this and I wonder what this could be. First attempt was to just iterate again, but apart from being non-optimal it's not enough to solve the problem.
As I plan on making a plugin system and sending events to interested plugins all the time, I wonder whether that's even feasible now.
I use
wasmtime 22.0.0
andwasmtime_wasi 22.0.0
btw.
nerdachse edited issue #8943:
Hey there!
Similar to #8670 (which I read), I have a problem with calling multiple functions of a
wasm component
.let info_func = { let mut exports: wasmtime::component::Exports = plugin.exports(&mut store); let mut register = exports .instance("test:guest/info") .expect(&format!("plugin@{path:?} to have info instance")); match register.typed_func::<(), (PluginInfo,)>("info") { Ok(info) => info, Err(e) => { eprintln!("plugin@{path:?} does not have an info function: {e}!"); continue; } } }; let info = info_func.call(&mut store, ()); println!("plugin@{path:?}: {info:?}"); // Scope the borrow of &mut store to limit its lifetime let init_func = { let mut exports: wasmtime::component::Exports = plugin.exports(&mut store); let mut register = exports .instance("test:guest/register") .expect(&format!("plugin@{:?} to have register instance", path)); match register.typed_func::<(), (String,)>("init") { Ok(init) => init, Err(e) => { eprintln!("plugin@{:?} does not have an init function: {}!", path, e); continue; } } }; // Now call the init function after the borrow from exports has ended let result = init_func.call(&mut store, ()).expect("init to be callable"); println!("plugin@{:?} result of init: {:?}", path, result);
gives me:
thread 'main' panicked at src/main.rs:121:53:
init to be callable: wasm trap: cannot enter component instanceNow I understand the problem but in #8670 it was said that there could be another solution for this and I wonder what this could be. First attempt was to just iterate again, but apart from being non-optimal it's not enough to solve the problem.
As I plan on making a plugin system and sending events to interested plugins all the time, I wonder whether that's even feasible now.
I use
wasmtime 22.0.0
andwasmtime_wasi 22.0.0
btw.
```[tasklist]Tasks
~~~
nerdachse edited issue #8943:
Hey there!
Similar to #8670 (which I read), I have a problem with calling multiple functions of a
wasm component
.let info_func = { let mut exports: wasmtime::component::Exports = plugin.exports(&mut store); let mut register = exports .instance("test:guest/info") .expect(&format!("plugin@{path:?} to have info instance")); match register.typed_func::<(), (PluginInfo,)>("info") { Ok(info) => info, Err(e) => { eprintln!("plugin@{path:?} does not have an info function: {e}!"); continue; } } }; let info = info_func.call(&mut store, ()); println!("plugin@{path:?}: {info:?}"); // Scope the borrow of &mut store to limit its lifetime let init_func = { let mut exports: wasmtime::component::Exports = plugin.exports(&mut store); let mut register = exports .instance("test:guest/register") .expect(&format!("plugin@{:?} to have register instance", path)); match register.typed_func::<(), (String,)>("init") { Ok(init) => init, Err(e) => { eprintln!("plugin@{:?} does not have an init function: {}!", path, e); continue; } } }; // Now call the init function after the borrow from exports has ended let result = init_func.call(&mut store, ()).expect("init to be callable"); println!("plugin@{:?} result of init: {:?}", path, result);
gives me:
thread 'main' panicked at src/main.rs:121:53:
init to be callable: wasm trap: cannot enter component instanceNow I understand the problem but in #8670 it was said that there could be another solution for this and I wonder what this could be. First attempt was to just iterate again, but apart from being non-optimal it's not enough to solve the problem.
As I plan on making a plugin system and sending events to interested plugins all the time, I wonder whether that's even feasible now.
I use
wasmtime 22.0.0
andwasmtime_wasi 22.0.0
btw.
alexcrichton commented on issue #8943:
You're missing a call to
TypedFunc::post_return
here which should be mentioned in theTypedFunc::call
documentation as well. If possible I'd recommend usingbindgen!
if it works for your use case.
nerdachse closed issue #8943:
Hey there!
Similar to #8670 (which I read), I have a problem with calling multiple functions of a
wasm component
.let info_func = { let mut exports: wasmtime::component::Exports = plugin.exports(&mut store); let mut register = exports .instance("test:guest/info") .expect(&format!("plugin@{path:?} to have info instance")); match register.typed_func::<(), (PluginInfo,)>("info") { Ok(info) => info, Err(e) => { eprintln!("plugin@{path:?} does not have an info function: {e}!"); continue; } } }; let info = info_func.call(&mut store, ()); println!("plugin@{path:?}: {info:?}"); // Scope the borrow of &mut store to limit its lifetime let init_func = { let mut exports: wasmtime::component::Exports = plugin.exports(&mut store); let mut register = exports .instance("test:guest/register") .expect(&format!("plugin@{:?} to have register instance", path)); match register.typed_func::<(), (String,)>("init") { Ok(init) => init, Err(e) => { eprintln!("plugin@{:?} does not have an init function: {}!", path, e); continue; } } }; // Now call the init function after the borrow from exports has ended let result = init_func.call(&mut store, ()).expect("init to be callable"); println!("plugin@{:?} result of init: {:?}", path, result);
gives me:
thread 'main' panicked at src/main.rs:121:53:
init to be callable: wasm trap: cannot enter component instanceNow I understand the problem but in #8670 it was said that there could be another solution for this and I wonder what this could be. First attempt was to just iterate again, but apart from being non-optimal it's not enough to solve the problem.
As I plan on making a plugin system and sending events to interested plugins all the time, I wonder whether that's even feasible now.
I use
wasmtime 22.0.0
andwasmtime_wasi 22.0.0
btw.
Last updated: Nov 22 2024 at 17:03 UTC