summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2021-04-10 23:48:47 +0100
committerAlex Orlenko <zxteam@protonmail.com>2021-04-27 00:29:38 +0100
commitc10169a38018038e0859aa7be1946e7606cea566 (patch)
tree4f13da21a1fd205c97a44164626b4bd3b7e4c1d5 /src
parentced808d5ab5777abf283a72f71c51ef8040b02f0 (diff)
downloadmlua-c10169a38018038e0859aa7be1946e7606cea566.zip
cargo fmt and other minor fixes
Diffstat (limited to 'src')
-rw-r--r--src/scope.rs35
-rw-r--r--src/types.rs1
-rw-r--r--src/userdata.rs1
-rw-r--r--src/util.rs8
-rw-r--r--src/value.rs1
5 files changed, 24 insertions, 22 deletions
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<Vec<(LuaRef<'lua>, Box<dyn Fn(LuaRef<'lua>) -> Vec<Box<dyn Any>> + 'lua>)>>,
+ destructors: RefCell<Vec<(LuaRef<'lua>, DestructorCallback<'lua>)>>,
_scope_invariant: PhantomData<Cell<&'scope ()>>,
}
+type DestructorCallback<'lua> = Box<dyn Fn(LuaRef<'lua>) -> Vec<Box<dyn Any>> + '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::<UserDataCell<T>>(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::<UserDataCell<()>>(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<'callback, 'scope>, 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<T: Any>(
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};