summaryrefslogtreecommitdiff
path: root/src/lua.rs
diff options
context:
space:
mode:
authorkyren <kerriganw@gmail.com>2018-02-11 08:51:17 -0500
committerkyren <kerriganw@gmail.com>2018-02-11 08:51:17 -0500
commitce7e8e61fd9849695527b3c0b04db8f7c7c94db1 (patch)
treeefba810062822e92bc65d84f0a8ffd467101f588 /src/lua.rs
parentda1e1625b3f8359454a20a44db9ed18a763e11f7 (diff)
downloadmlua-ce7e8e61fd9849695527b3c0b04db8f7c7c94db1.zip
shave this yak some more, make `Callback` type alias have two lifetimes
Diffstat (limited to 'src/lua.rs')
-rw-r--r--src/lua.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/lua.rs b/src/lua.rs
index 9dcd438..9526301 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -973,7 +973,7 @@ impl Lua {
fn create_callback_function<'lua, 'callback>(
&'lua self,
- func: Callback<'callback>,
+ func: Callback<'callback, 'static>,
) -> Result<Function<'lua>> {
unsafe extern "C" fn callback_call_impl(state: *mut ffi::lua_State) -> c_int {
callback_error(state, || {
@@ -1066,16 +1066,11 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
R: ToLuaMulti<'callback>,
F: 'scope + Fn(&'callback Lua, A) -> Result<R>,
{
- let f: Box<
- Fn(&'callback Lua, MultiValue<'callback>) -> Result<MultiValue<'callback>> + '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 f: Box<
- Fn(&'callback Lua, MultiValue<'callback>) -> Result<MultiValue<'callback>>,
- > = mem::transmute(f);
-
+ let f = Box::new(move |lua, args| {
+ func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
+ });
+ let f = mem::transmute::<Callback<'callback, 'scope>, Callback<'callback, 'static>>(f);
let mut f = self.lua.create_callback_function(f)?;
f.0.drop_unref = false;