-
Notifications
You must be signed in to change notification settings - Fork 117
Unable to pass functions as arguments to create_function
#73
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
Comments
Edit: Whoops, I misread this entirely, I was out last night 🍸 and replying on my phone, and replied without thinking. Let me try this again: Try something like this:
You can't accept a Lua function as a function pointer because it has to be a handle into the Lua state. Lua function handles are just |
Ah ha, that seems to work! Thank you so much! |
Hi, I seem to have run into another issue while trying to store a copy of the function: Code used: fn setup_module_globals(&mut self) -> rlua::Result<()> {
let on_event_function = self.lua.create_function(|_, (name, handler): (String, rlua::Function)| {
self.events.entry(String::from(name)).or_insert_with(Vec::new).push(handler.clone());
Ok(())
})?;
self.lua.globals().set("on_event", on_event_function.clone())
} Error given:
It's due to the calling of |
You're trying to create a Lua closure that captures I think I see what you're trying to do, and there are a lot of ways to accomplish this. I can't know which one is the best for you, but I can roughly describe some of the solutions. Ultimately, you need to put some thought into what owns things like
(side note: there's an open issue about optionally adding a lifetime to You can fix the There are two rules about
There is, however, a way around these restrictions. One potential solution that prevents you from needing an Arc<Mutex<>> is just to use Generally when you start running into lifetime problems with |
I've also attempted with
rlua::Function
, but that seems to not work either.Error:
Is there someway to pass a function that I'm missing?
The text was updated successfully, but these errors were encountered: