mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
Fix clippy warnings
This commit is contained in:
@@ -70,7 +70,7 @@ pub fn probe_lua() -> Option<PathBuf> {
|
||||
.probe(alt_probe);
|
||||
}
|
||||
|
||||
lua.expect(&format!("cannot find Lua {} using `pkg-config`", ver))
|
||||
lua.unwrap_or_else(|_| panic!("cannot find Lua {} using `pkg-config`", ver))
|
||||
.include_paths
|
||||
.get(0)
|
||||
.cloned()
|
||||
|
||||
@@ -110,10 +110,10 @@ unsafe fn compat53_pushglobalfuncname(L: *mut lua_State, ar: *mut lua_Debug) ->
|
||||
if compat53_findfield(L, top + 1, 2) != 0 {
|
||||
lua_copy(L, -1, top + 1); // move name to proper place
|
||||
lua_pop(L, 2); // remove pushed values
|
||||
return 1;
|
||||
1
|
||||
} else {
|
||||
lua_settop(L, top); // remove function and global table
|
||||
return 0;
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-16
@@ -2,7 +2,6 @@
|
||||
//!
|
||||
//! Based on github.com/keplerproject/lua-compat-5.3
|
||||
|
||||
use std::convert::TryInto;
|
||||
use std::ffi::CStr;
|
||||
use std::mem;
|
||||
use std::os::raw::{c_char, c_int, c_void};
|
||||
@@ -51,7 +50,7 @@ unsafe fn compat53_findfield(L: *mut lua_State, objidx: c_int, level: c_int) ->
|
||||
}
|
||||
lua_pop(L, 1); // remove value
|
||||
}
|
||||
return 0; // not found
|
||||
0 // not found
|
||||
}
|
||||
|
||||
unsafe fn compat53_pushglobalfuncname(
|
||||
@@ -66,10 +65,10 @@ unsafe fn compat53_pushglobalfuncname(
|
||||
if compat53_findfield(L, top + 1, 2) != 0 {
|
||||
lua_copy(L, -1, top + 1); // move name to proper place
|
||||
lua_pop(L, 2); // remove pushed values
|
||||
return 1;
|
||||
1
|
||||
} else {
|
||||
lua_settop(L, top); // remove function and global table
|
||||
return 0;
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,13 +76,11 @@ unsafe fn compat53_pushfuncname(L: *mut lua_State, level: c_int, ar: *mut lua_De
|
||||
if !(*ar).name.is_null() {
|
||||
// is there a name?
|
||||
lua_pushfstring(L, cstr!("function '%s'"), (*ar).name);
|
||||
} else if compat53_pushglobalfuncname(L, level, ar) != 0 {
|
||||
lua_pushfstring(L, cstr!("function '%s'"), lua_tostring(L, -1));
|
||||
lua_remove(L, -2); // remove name
|
||||
} else {
|
||||
if compat53_pushglobalfuncname(L, level, ar) != 0 {
|
||||
lua_pushfstring(L, cstr!("function '%s'"), lua_tostring(L, -1));
|
||||
lua_remove(L, -2); // remove name
|
||||
} else {
|
||||
lua_pushliteral(L, "?");
|
||||
}
|
||||
lua_pushliteral(L, "?");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +174,6 @@ pub unsafe fn lua_geti(L: *mut lua_State, mut idx: c_int, n: lua_Integer) -> c_i
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_rawgeti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int {
|
||||
let n = n.try_into().expect("cannot convert index to lua_Integer");
|
||||
lua_rawgeti_(L, idx, n)
|
||||
}
|
||||
|
||||
@@ -213,7 +209,6 @@ pub unsafe fn lua_seti(L: *mut lua_State, mut idx: c_int, n: lua_Integer) {
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn lua_rawseti(L: *mut lua_State, idx: c_int, n: lua_Integer) {
|
||||
let n = n.try_into().expect("cannot convert index from lua_Integer");
|
||||
lua_rawseti_(L, idx, n)
|
||||
}
|
||||
|
||||
@@ -366,10 +361,8 @@ pub unsafe fn luaL_loadbufferx(
|
||||
if !ok {
|
||||
return LUA_ERRSYNTAX;
|
||||
}
|
||||
} else {
|
||||
if luau_load(L, name, data, size, 0) != 0 {
|
||||
return LUA_ERRSYNTAX;
|
||||
}
|
||||
} else if luau_load(L, name, data, size, 0) != 0 {
|
||||
return LUA_ERRSYNTAX;
|
||||
}
|
||||
LUA_OK
|
||||
}
|
||||
|
||||
+6
-6
@@ -1351,7 +1351,7 @@ impl Lua {
|
||||
{
|
||||
let func = RefCell::new(func);
|
||||
self.create_function(move |lua, args| {
|
||||
(&mut *func
|
||||
(*func
|
||||
.try_borrow_mut()
|
||||
.map_err(|_| Error::RecursiveMutCallback)?)(lua, args)
|
||||
})
|
||||
@@ -2613,12 +2613,12 @@ impl Lua {
|
||||
match option.to_str() {
|
||||
Ok("collect") => {
|
||||
ffi::lua_gc(state, ffi::LUA_GCCOLLECT, 0);
|
||||
return 0;
|
||||
0
|
||||
}
|
||||
Ok("count") => {
|
||||
let n = ffi::lua_gc(state, ffi::LUA_GCCOUNT, 0);
|
||||
ffi::lua_pushnumber(state, n as ffi::lua_Number);
|
||||
return 1;
|
||||
1
|
||||
}
|
||||
// TODO: More variants
|
||||
_ => ffi::luaL_error(
|
||||
@@ -2629,7 +2629,7 @@ impl Lua {
|
||||
}
|
||||
|
||||
fn lua_require(lua: &Lua, name: Option<std::string::String>) -> Result<Value> {
|
||||
let name = name.ok_or(Error::RuntimeError("name is nil".into()))?;
|
||||
let name = name.ok_or_else(|| Error::RuntimeError("name is nil".into()))?;
|
||||
|
||||
// Find module in the cache
|
||||
let loaded = unsafe {
|
||||
@@ -2651,8 +2651,8 @@ impl Lua {
|
||||
}
|
||||
|
||||
let mut source = None;
|
||||
for path in search_path.split(";") {
|
||||
if let Ok(buf) = std::fs::read(path.replacen("?", &name, 1)) {
|
||||
for path in search_path.split(';') {
|
||||
if let Ok(buf) = std::fs::read(path.replacen('?', &name, 1)) {
|
||||
source = Some(buf);
|
||||
break;
|
||||
}
|
||||
|
||||
+3
-3
@@ -103,7 +103,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
|
||||
{
|
||||
let func = RefCell::new(func);
|
||||
self.create_function(move |lua, args| {
|
||||
(&mut *func
|
||||
(*func
|
||||
.try_borrow_mut()
|
||||
.map_err(|_| Error::RecursiveMutCallback)?)(lua, args)
|
||||
})
|
||||
@@ -306,7 +306,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
|
||||
let mut data = data
|
||||
.try_borrow_mut()
|
||||
.map_err(|_| Error::UserDataBorrowMutError)?;
|
||||
(&mut *method)(lua, &mut *data, args)
|
||||
(*method)(lua, &mut *data, args)
|
||||
});
|
||||
unsafe { scope.create_callback(f) }
|
||||
}
|
||||
@@ -314,7 +314,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
|
||||
NonStaticMethod::FunctionMut(function) => {
|
||||
let function = RefCell::new(function);
|
||||
let f = Box::new(move |lua, args| {
|
||||
(&mut *function
|
||||
(*function
|
||||
.try_borrow_mut()
|
||||
.map_err(|_| Error::RecursiveMutCallback)?)(
|
||||
lua, args
|
||||
|
||||
Reference in New Issue
Block a user