diff --git a/src/lua.rs b/src/lua.rs index e4b44c1..9dcd438 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -1066,15 +1066,17 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { R: ToLuaMulti<'callback>, F: 'scope + Fn(&'callback Lua, A) -> Result, { - unsafe { - let f: Box< - Fn(&'callback Lua, MultiValue<'callback>) -> Result> + 'scope, - > = Box::new(move |lua, args| { - func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) - }); + let f: Box< + Fn(&'callback Lua, MultiValue<'callback>) -> Result> + 'scope, + > = Box::new(move |lua, args| func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)); + unsafe { // SCARY, we are transmuting the 'scope lifetime to 'static. - let mut f = self.lua.create_callback_function(mem::transmute(f))?; + let f: Box< + Fn(&'callback Lua, MultiValue<'callback>) -> Result>, + > = mem::transmute(f); + + let mut f = self.lua.create_callback_function(f)?; f.0.drop_unref = false; let mut destructors = self.destructors.borrow_mut();