-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modify unserializable struct in plugin runtime without global state #196
Comments
Thanks for the heads-up! What do you mean by modifying a host struct exactly? The global state it is modifying in that example lives within the plugin, so wouldn't affect the host at all. Could you explain what you would like to achieve? |
this fp-bindgen/examples/example-rust-wasmer2-runtime/src/spec/mod.rs Lines 183 to 190 in 4e95816
the GLOBAL_STATE can also hold an unserializable struct, like a egui context. thus i can let plugin control ui via such import function. but i want to avoid GLOBAL_STATE style. {
let mut rust_val = 0;
lua.scope(|scope| {
// We create a 'sketchy' Lua callback that holds a mutable reference to the variable
// `rust_val`. Outside of a `Lua::scope` call, this would not be allowed
// because it could be unsafe.
lua.globals().set(
"sketchy",
scope.create_function_mut(|_, ()| {
rust_val = 42;
Ok(())
})?,
)?;
lua.load("sketchy()").exec()
})?;
assert_eq!(rust_val, 42);
} |
Oh, you're right, that's my bad. Yes, that one is indeed kept in host memory. Frankly, it's not something we support very well, since the use cases we focus on are more situations where the plugin does things for the host without assuming persistence. Still, I think it's a useful request to consider when we eventually migrate to Wasmer 4. |
examples/example-rust-wasmer2-runtime/src/spec/mod.rs
gives a way for plugin to modify a host struct using global state. can this be done without global state?BTW, the
example-rust-runtime/spec/mod.rs
in readme does't exist.The text was updated successfully, but these errors were encountered: