Clean up the debug related functions

This commit is contained in:
William Venner 2021-10-10 20:04:12 +01:00
parent 8c554cfad9
commit d411658966
4 changed files with 24 additions and 6 deletions

2
Cargo.lock generated
View File

@ -109,7 +109,7 @@ dependencies = [
[[package]] [[package]]
name = "gmod" name = "gmod"
version = "4.0.3" version = "5.0.0"
dependencies = [ dependencies = [
"cfg_table", "cfg_table",
"cstr", "cstr",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "gmod" name = "gmod"
version = "4.0.3" version = "5.0.0"
authors = ["William Venner <william@venner.io>"] authors = ["William Venner <william@venner.io>"]
edition = "2018" edition = "2018"
license = "MIT" license = "MIT"

View File

@ -71,10 +71,10 @@ impl LuaError {
} }
lazy_static::lazy_static! { lazy_static::lazy_static! {
pub(crate) static ref LUA_SHARED: LuaShared = LuaShared::import(); pub static ref LUA_SHARED: LuaShared = LuaShared::import();
} }
pub(crate) struct LuaShared { pub struct LuaShared {
pub lual_newstate: Symbol<'static, unsafe extern "C-unwind" fn() -> LuaState>, pub lual_newstate: Symbol<'static, unsafe extern "C-unwind" fn() -> LuaState>,
pub lual_openlibs: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState)>, pub lual_openlibs: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState)>,
pub lual_loadfile: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, path: LuaString) -> i32>, pub lual_loadfile: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, path: LuaString) -> i32>,

View File

@ -392,7 +392,16 @@ impl LuaState {
unreachable!() unreachable!()
} }
pub unsafe fn debug_get_info(&self, what: LuaString) -> Option<LuaDebug> { pub unsafe fn debug_getinfo_from_ar(&self, ar: &mut LuaDebug, what: LuaString) -> Result<(), ()> {
if (LUA_SHARED.lua_getinfo)(*self, what, ar as *mut LuaDebug) != 0 {
Ok(())
} else {
Err(())
}
}
/// `what` should start with `>` and pop a function off the stack
pub unsafe fn debug_getinfo_from_stack(&self, what: LuaString) -> Option<LuaDebug> {
let mut ar = MaybeUninit::uninit(); let mut ar = MaybeUninit::uninit();
if (LUA_SHARED.lua_getinfo)(*self, what, ar.as_mut_ptr()) != 0 { if (LUA_SHARED.lua_getinfo)(*self, what, ar.as_mut_ptr()) != 0 {
Some(ar.assume_init()) Some(ar.assume_init())
@ -401,7 +410,16 @@ impl LuaState {
} }
} }
pub unsafe fn debug_get_invocation_info(&self, level: i32, what: LuaString) -> Option<LuaDebug> { pub unsafe fn get_stack_at(&self, level: i32) -> Option<LuaDebug> {
let mut ar = MaybeUninit::uninit();
if (LUA_SHARED.lua_getstack)(*self, level, ar.as_mut_ptr()) != 0 {
Some(ar.assume_init())
} else {
None
}
}
pub unsafe fn debug_getinfo_at(&self, level: i32, what: LuaString) -> Option<LuaDebug> {
let mut ar = MaybeUninit::uninit(); let mut ar = MaybeUninit::uninit();
if (LUA_SHARED.lua_getstack)(*self, level, ar.as_mut_ptr()) != 0 { if (LUA_SHARED.lua_getstack)(*self, level, ar.as_mut_ptr()) != 0 {
if (LUA_SHARED.lua_getinfo)(*self, what, ar.as_mut_ptr()) != 0 { if (LUA_SHARED.lua_getinfo)(*self, what, ar.as_mut_ptr()) != 0 {