Repository navigation
|
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? |
Answered by
khvzak
Jun 18, 2023
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(())?; |
4 replies
Answer selected by
DasLixou
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can store arbitrary data in Lua itself using the
app_datacontainer.eg:
However for your case probably would be easier to store function inside registry with given name: