diff --git a/src/scope.rs b/src/scope.rs index 640886f..70d6116 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -34,13 +34,14 @@ use { /// See [`Lua::scope`] for more details. /// /// [`Lua::scope`]: struct.Lua.html#method.scope -#[allow(clippy::type_complexity)] pub struct Scope<'lua, 'scope> { lua: &'lua Lua, - destructors: RefCell, Box) -> Vec> + 'lua>)>>, + destructors: RefCell, DestructorCallback<'lua>)>>, _scope_invariant: PhantomData>, } +type DestructorCallback<'lua> = Box) -> Vec> + 'lua>; + impl<'lua, 'scope> Scope<'lua, 'scope> { pub(crate) fn new(lua: &'lua Lua) -> Scope<'lua, 'scope> { Scope { @@ -184,7 +185,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { #[cfg(any(feature = "lua51", feature = "luajit"))] let newtable = self.lua.create_table()?; - self.destructors.borrow_mut().push((ud.0.clone(), Box::new(move |u| { + let destructor: DestructorCallback = Box::new(move |u| { let state = u.lua.state; assert_stack(state, 2); u.lua.push_ref(&u); @@ -199,7 +200,10 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { // We know the destructor has not run yet because we hold a reference to the // userdata. vec![Box::new(take_userdata::>(state))] - }))); + }); + self.destructors + .borrow_mut() + .push((ud.0.clone(), destructor)); Ok(ud) } @@ -399,7 +403,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { #[cfg(any(feature = "lua51", feature = "luajit"))] let newtable = lua.create_table()?; - self.destructors.borrow_mut().push((ud.0.clone(), Box::new(move |ud| { + let destructor: DestructorCallback = Box::new(move |ud| { // We know the destructor has not run yet because we hold a reference to the userdata. let state = ud.lua.state; assert_stack(state, 2); @@ -419,7 +423,10 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { ffi::lua_setuservalue(state, -2); vec![Box::new(take_userdata::>(state))] - }))); + }); + self.destructors + .borrow_mut() + .push((ud.0.clone(), destructor)); Ok(ud) } @@ -437,7 +444,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { let f = mem::transmute::, Callback<'lua, 'static>>(f); let f = self.lua.create_callback(f)?; - self.destructors.borrow_mut().push((f.0.clone(), Box::new(|f| { + let destructor: DestructorCallback = Box::new(|f| { let state = f.lua.state; assert_stack(state, 3); f.lua.push_ref(&f); @@ -456,7 +463,11 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { ffi::lua_pop(state, 1); vec![Box::new(ud1), Box::new(ud2)] - }))); + }); + self.destructors + .borrow_mut() + .push((f.0.clone(), destructor)); + Ok(f) } @@ -471,8 +482,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { // We need to pre-allocate strings to avoid failures in destructor. let get_poll_str = self.lua.create_string("get_poll")?; let poll_str = self.lua.create_string("poll")?; - - self.destructors.borrow_mut().push((f.0.clone(), Box::new(move |f| { + let destructor: DestructorCallback = Box::new(move |f| { let state = f.lua.state; assert_stack(state, 4); f.lua.push_ref(&f); @@ -520,7 +530,10 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { } data - }))); + }); + self.destructors + .borrow_mut() + .push((f.0.clone(), destructor)); Ok(f) } diff --git a/src/types.rs b/src/types.rs index 79b6293..7621c43 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,3 @@ -// OK use std::cell::RefCell; use std::os::raw::{c_int, c_void}; use std::sync::{Arc, Mutex}; diff --git a/src/userdata.rs b/src/userdata.rs index f3d01c9..a2082e7 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -1,4 +1,3 @@ -// OK use std::cell::{Ref, RefMut}; use std::fmt; use std::hash::{Hash, Hasher}; diff --git a/src/util.rs b/src/util.rs index cf351dc..e2c85ab 100644 --- a/src/util.rs +++ b/src/util.rs @@ -385,14 +385,6 @@ pub unsafe fn get_wrapped_error(state: *mut ffi::lua_State, index: c_int) -> *co &(*ud).0 } -#[no_mangle] -pub unsafe extern "C" fn mlua_get_wrapped_error( - state: *mut ffi::lua_State, - index: c_int, -) -> *const c_void { - get_wrapped_error(state, index) as *const c_void -} - // Initialize the internal (with __gc) metatable for a type T pub unsafe fn init_gc_metatable_for( state: *mut ffi::lua_State, diff --git a/src/value.rs b/src/value.rs index 082436e..ba2e13e 100644 --- a/src/value.rs +++ b/src/value.rs @@ -1,4 +1,3 @@ -// OK use std::iter::{self, FromIterator}; use std::{slice, str, vec};