Fix some clippy warnings & minor changes
This commit is contained in:
parent
decb5b9e37
commit
5a7ad9f7cd
|
@ -250,6 +250,7 @@ end
|
||||||
|
|
||||||
#[cfg(any(feature = "lua51", feature = "luajit"))]
|
#[cfg(any(feature = "lua51", feature = "luajit"))]
|
||||||
pub unsafe fn lua_arith(L: *mut lua_State, op: c_int) {
|
pub unsafe fn lua_arith(L: *mut lua_State, op: c_int) {
|
||||||
|
#[allow(clippy::manual_range_contains)]
|
||||||
if op < LUA_OPADD || op > LUA_OPUNM {
|
if op < LUA_OPADD || op > LUA_OPUNM {
|
||||||
luaL_error(L, cstr!("invalid 'op' argument for lua_arith"));
|
luaL_error(L, cstr!("invalid 'op' argument for lua_arith"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1557,7 +1557,7 @@ impl Lua {
|
||||||
let mut extra_tables_count = 0;
|
let mut extra_tables_count = 0;
|
||||||
|
|
||||||
let mut field_getters_index = None;
|
let mut field_getters_index = None;
|
||||||
let has_field_getters = fields.field_getters.len() > 0;
|
let has_field_getters = !fields.field_getters.is_empty();
|
||||||
if has_field_getters {
|
if has_field_getters {
|
||||||
protect_lua_closure(self.state, 0, 1, |state| {
|
protect_lua_closure(self.state, 0, 1, |state| {
|
||||||
ffi::lua_newtable(state);
|
ffi::lua_newtable(state);
|
||||||
|
@ -1575,7 +1575,7 @@ impl Lua {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut field_setters_index = None;
|
let mut field_setters_index = None;
|
||||||
let has_field_setters = fields.field_setters.len() > 0;
|
let has_field_setters = !fields.field_setters.is_empty();
|
||||||
if has_field_setters {
|
if has_field_setters {
|
||||||
protect_lua_closure(self.state, 0, 1, |state| {
|
protect_lua_closure(self.state, 0, 1, |state| {
|
||||||
ffi::lua_newtable(state);
|
ffi::lua_newtable(state);
|
||||||
|
@ -1594,9 +1594,9 @@ impl Lua {
|
||||||
|
|
||||||
let mut methods_index = None;
|
let mut methods_index = None;
|
||||||
#[cfg(feature = "async")]
|
#[cfg(feature = "async")]
|
||||||
let has_methods = methods.methods.len() > 0 || methods.async_methods.len() > 0;
|
let has_methods = !methods.methods.is_empty() || !methods.async_methods.is_empty();
|
||||||
#[cfg(not(feature = "async"))]
|
#[cfg(not(feature = "async"))]
|
||||||
let has_methods = methods.methods.len() > 0;
|
let has_methods = !methods.methods.is_empty();
|
||||||
if has_methods {
|
if has_methods {
|
||||||
protect_lua_closure(self.state, 0, 1, |state| {
|
protect_lua_closure(self.state, 0, 1, |state| {
|
||||||
ffi::lua_newtable(state);
|
ffi::lua_newtable(state);
|
||||||
|
@ -2546,6 +2546,7 @@ impl<'lua, T: 'static + UserData> StaticUserDataMethods<'lua, T> {
|
||||||
struct StaticUserDataFields<'lua, T: 'static + UserData> {
|
struct StaticUserDataFields<'lua, T: 'static + UserData> {
|
||||||
field_getters: Vec<(Vec<u8>, Callback<'lua, 'static>)>,
|
field_getters: Vec<(Vec<u8>, Callback<'lua, 'static>)>,
|
||||||
field_setters: Vec<(Vec<u8>, Callback<'lua, 'static>)>,
|
field_setters: Vec<(Vec<u8>, Callback<'lua, 'static>)>,
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
meta_fields: Vec<(
|
meta_fields: Vec<(
|
||||||
MetaMethod,
|
MetaMethod,
|
||||||
Box<dyn Fn(&'lua Lua) -> Result<Value<'lua>> + 'static>,
|
Box<dyn Fn(&'lua Lua) -> Result<Value<'lua>> + 'static>,
|
||||||
|
|
11
src/scope.rs
11
src/scope.rs
|
@ -258,7 +258,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
|
||||||
if ffi::lua_getmetatable(lua.state, -1) == 0 {
|
if ffi::lua_getmetatable(lua.state, -1) == 0 {
|
||||||
return Err(Error::UserDataTypeMismatch);
|
return Err(Error::UserDataTypeMismatch);
|
||||||
}
|
}
|
||||||
ffi::lua_pushstring(lua.state, cstr!("__mlua"));
|
ffi::lua_pushstring(lua.state, cstr!("__mlua_ptr"));
|
||||||
if ffi::lua_rawget(lua.state, -2) == ffi::LUA_TLIGHTUSERDATA {
|
if ffi::lua_rawget(lua.state, -2) == ffi::LUA_TLIGHTUSERDATA {
|
||||||
let ud_ptr = ffi::lua_touserdata(lua.state, -1);
|
let ud_ptr = ffi::lua_touserdata(lua.state, -1);
|
||||||
if ud_ptr == check_data.as_ptr() as *mut c_void {
|
if ud_ptr == check_data.as_ptr() as *mut c_void {
|
||||||
|
@ -330,7 +330,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
|
||||||
ffi::lua_newtable(state);
|
ffi::lua_newtable(state);
|
||||||
|
|
||||||
// Add internal metamethod to store reference to the data
|
// Add internal metamethod to store reference to the data
|
||||||
ffi::lua_pushstring(state, cstr!("__mlua"));
|
ffi::lua_pushstring(state, cstr!("__mlua_ptr"));
|
||||||
ffi::lua_pushlightuserdata(lua.state, data.as_ptr() as *mut c_void);
|
ffi::lua_pushlightuserdata(lua.state, data.as_ptr() as *mut c_void);
|
||||||
ffi::lua_rawset(state, -3);
|
ffi::lua_rawset(state, -3);
|
||||||
})?;
|
})?;
|
||||||
|
@ -353,7 +353,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
|
||||||
let metatable_index = ffi::lua_absindex(lua.state, -1);
|
let metatable_index = ffi::lua_absindex(lua.state, -1);
|
||||||
|
|
||||||
let mut field_getters_index = None;
|
let mut field_getters_index = None;
|
||||||
if ud_fields.field_getters.len() > 0 {
|
if !ud_fields.field_getters.is_empty() {
|
||||||
protect_lua_closure(lua.state, 0, 1, |state| {
|
protect_lua_closure(lua.state, 0, 1, |state| {
|
||||||
ffi::lua_newtable(state);
|
ffi::lua_newtable(state);
|
||||||
})?;
|
})?;
|
||||||
|
@ -369,7 +369,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut field_setters_index = None;
|
let mut field_setters_index = None;
|
||||||
if ud_fields.field_setters.len() > 0 {
|
if !ud_fields.field_setters.is_empty() {
|
||||||
protect_lua_closure(lua.state, 0, 1, |state| {
|
protect_lua_closure(lua.state, 0, 1, |state| {
|
||||||
ffi::lua_newtable(state);
|
ffi::lua_newtable(state);
|
||||||
})?;
|
})?;
|
||||||
|
@ -385,7 +385,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut methods_index = None;
|
let mut methods_index = None;
|
||||||
if ud_methods.methods.len() > 0 {
|
if !ud_methods.methods.is_empty() {
|
||||||
// Create table used for methods lookup
|
// Create table used for methods lookup
|
||||||
protect_lua_closure(lua.state, 0, 1, |state| {
|
protect_lua_closure(lua.state, 0, 1, |state| {
|
||||||
ffi::lua_newtable(state);
|
ffi::lua_newtable(state);
|
||||||
|
@ -738,6 +738,7 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> for NonStaticUserDataMethods<'l
|
||||||
struct NonStaticUserDataFields<'lua, T: UserData> {
|
struct NonStaticUserDataFields<'lua, T: UserData> {
|
||||||
field_getters: Vec<(Vec<u8>, NonStaticMethod<'lua, T>)>,
|
field_getters: Vec<(Vec<u8>, NonStaticMethod<'lua, T>)>,
|
||||||
field_setters: Vec<(Vec<u8>, NonStaticMethod<'lua, T>)>,
|
field_setters: Vec<(Vec<u8>, NonStaticMethod<'lua, T>)>,
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
meta_fields: Vec<(MetaMethod, Box<dyn Fn(&'lua Lua) -> Result<Value<'lua>>>)>,
|
meta_fields: Vec<(MetaMethod, Box<dyn Fn(&'lua Lua) -> Result<Value<'lua>>>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,9 @@ impl MetaMethod {
|
||||||
MetaMethod::Custom(name) if name == "__metatable" => {
|
MetaMethod::Custom(name) if name == "__metatable" => {
|
||||||
Err(Error::MetaMethodRestricted(name))
|
Err(Error::MetaMethodRestricted(name))
|
||||||
}
|
}
|
||||||
MetaMethod::Custom(name) if name == "__mlua" => Err(Error::MetaMethodRestricted(name)),
|
MetaMethod::Custom(name) if name.starts_with("__mlua") => {
|
||||||
|
Err(Error::MetaMethodRestricted(name))
|
||||||
|
}
|
||||||
_ => Ok(self),
|
_ => Ok(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -714,7 +716,9 @@ impl<'lua> AnyUserData<'lua> {
|
||||||
/// Returns a metatable of this `UserData`.
|
/// Returns a metatable of this `UserData`.
|
||||||
///
|
///
|
||||||
/// Returned [`UserDataMetatable`] object wraps the original metatable and
|
/// Returned [`UserDataMetatable`] object wraps the original metatable and
|
||||||
/// allows to provide safe access to it methods.
|
/// provides safe access to it methods.
|
||||||
|
///
|
||||||
|
/// For `T: UserData + 'static` returned metatable is shared among all instances of type `T`.
|
||||||
///
|
///
|
||||||
/// [`UserDataMetatable`]: struct.UserDataMetatable.html
|
/// [`UserDataMetatable`]: struct.UserDataMetatable.html
|
||||||
pub fn get_metatable(&self) -> Result<UserDataMetatable<'lua>> {
|
pub fn get_metatable(&self) -> Result<UserDataMetatable<'lua>> {
|
||||||
|
|
Loading…
Reference in New Issue