diff --git a/src/lua.rs b/src/lua.rs index a9181b5..c14d364 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -34,7 +34,7 @@ pub struct Scope<'lua, 'scope> { lua: &'lua Lua, destructors: RefCell Box>>>, // 'scope lifetime must be invariant - _phantom: PhantomData<&'scope mut &'scope ()>, + _scope: PhantomData<&'scope mut &'scope ()>, } // Data associated with the main lua_State via lua_getextraspace. @@ -265,11 +265,14 @@ impl Lua { /// /// [`ToLua`]: trait.ToLua.html /// [`ToLuaMulti`]: trait.ToLuaMulti.html - pub fn create_function<'lua, A, R, F>(&'lua self, mut func: F) -> Result> + pub fn create_function<'lua, 'callback, A, R, F>( + &'lua self, + mut func: F, + ) -> Result> where - A: FromLuaMulti<'lua>, - R: ToLuaMulti<'lua>, - F: 'static + Send + FnMut(&'lua Lua, A) -> Result, + A: FromLuaMulti<'callback>, + R: ToLuaMulti<'callback>, + F: 'static + Send + FnMut(&'callback Lua, A) -> Result, { self.create_callback_function(Box::new(move |lua, args| { func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) @@ -336,7 +339,7 @@ impl Lua { let scope = Scope { lua: self, destructors: RefCell::new(Vec::new()), - _phantom: PhantomData, + _scope: PhantomData, }; let r = f(&scope); drop(scope); @@ -958,7 +961,10 @@ impl Lua { } } - fn create_callback_function<'lua>(&'lua self, func: Callback<'lua>) -> Result> { + fn create_callback_function<'lua, 'callback>( + &'lua self, + func: Callback<'callback>, + ) -> Result> { unsafe extern "C" fn callback_call_impl(state: *mut ffi::lua_State) -> c_int { if ffi::lua_type(state, ffi::lua_upvalueindex(1)) == ffi::LUA_TNIL { ffi::lua_pushstring(state, cstr!("rust callback has been destructed")); @@ -1048,16 +1054,18 @@ impl Lua { } impl<'lua, 'scope> Scope<'lua, 'scope> { - pub fn create_function(&self, mut func: F) -> Result> + pub fn create_function<'callback, A, R, F>(&self, mut func: F) -> Result> where - A: FromLuaMulti<'lua>, - R: ToLuaMulti<'lua>, - F: 'scope + FnMut(&'lua Lua, A) -> Result, + A: FromLuaMulti<'callback>, + R: ToLuaMulti<'callback>, + F: 'scope + FnMut(&'callback Lua, A) -> Result, { unsafe { - let f: Box) -> Result>> = Box::new( - move |lua, args| func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua), - ); + let f: Box< + FnMut(&'callback Lua, MultiValue<'callback>) -> Result>, + > = Box::new(move |lua, args| { + func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) + }); // SCARY, we are transmuting away the 'static requirement let mut f = self.lua.create_callback_function(mem::transmute(f))?;