Use lua_iscfunction instead of lua_getinfo in `Function::environment()`

This commit is contained in:
Alex Orlenko 2023-06-08 09:33:48 +01:00
parent 03b6dfb2c3
commit cf0524aa23
No known key found for this signature in database
GPG Key ID: 4C150C250863B96D
1 changed files with 2 additions and 22 deletions

View File

@ -303,17 +303,7 @@ impl<'lua> Function<'lua> {
assert_stack(state, 1);
lua.push_ref(&self.0);
let mut ar: ffi::lua_Debug = mem::zeroed();
#[cfg(not(feature = "luau"))]
{
ffi::lua_pushvalue(state, -1);
ffi::lua_getinfo(state, cstr!(">S"), &mut ar);
}
#[cfg(feature = "luau")]
ffi::lua_getinfo(state, -1, cstr!("s"), &mut ar);
if ptr_to_cstr_bytes(ar.what) == Some(b"C") {
if ffi::lua_iscfunction(state, -1) != 0 {
return None;
}
@ -350,17 +340,7 @@ impl<'lua> Function<'lua> {
check_stack(state, 2)?;
lua.push_ref(&self.0);
let mut ar: ffi::lua_Debug = mem::zeroed();
#[cfg(not(feature = "luau"))]
{
ffi::lua_pushvalue(state, -1);
ffi::lua_getinfo(state, cstr!(">S"), &mut ar);
}
#[cfg(feature = "luau")]
ffi::lua_getinfo(state, -1, cstr!("s"), &mut ar);
if ptr_to_cstr_bytes(ar.what) == Some(b"C") {
if ffi::lua_iscfunction(state, -1) != 0 {
return Ok(false);
}