-
Hello! I made a rust function and made it accessible to my lua script by setting it as a function in globals. feature("my_feature", function ()
end) fn feature(_: &Lua, (name, callback): (String, LuaFunction)) -> LuaResult<()> {
println!("Registered feature {name:?}");
Ok(())
} Now I need to somehow store the callback inside a HashMap and wonder how I would get a mutable reference to a data structure such that it can be shared and used from this rust function. Is there any easy way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You can store arbitrary data in Lua itself using the eg: let map = HashMap::<String, RegistryKey>::new();
lua.set_app_data(map); However for your case probably would be easier to store function inside registry with given name: lua.set_named_registry_value(&name, callback)?;
// Call previously saved function
lua.named_registry_value::<Function>(&name)?.call(())?; |
Beta Was this translation helpful? Give feedback.
You can store arbitrary data in Lua itself using the
app_data
container.eg:
However for your case probably would be easier to store function inside registry with given name: