diff --git a/Cargo.lock b/Cargo.lock index d96d1b7..586811c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,7 +109,7 @@ dependencies = [ [[package]] name = "gmod" -version = "4.0.3" +version = "5.0.0" dependencies = [ "cfg_table", "cstr", diff --git a/gmod/Cargo.toml b/gmod/Cargo.toml index d2d2359..e2d06df 100644 --- a/gmod/Cargo.toml +++ b/gmod/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gmod" -version = "4.0.3" +version = "5.0.0" authors = ["William Venner "] edition = "2018" license = "MIT" diff --git a/gmod/src/lua/import.rs b/gmod/src/lua/import.rs index 979f534..6e83cd9 100644 --- a/gmod/src/lua/import.rs +++ b/gmod/src/lua/import.rs @@ -71,10 +71,10 @@ impl LuaError { } 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_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>, diff --git a/gmod/src/lua/lua_state.rs b/gmod/src/lua/lua_state.rs index 75f7544..3814e61 100644 --- a/gmod/src/lua/lua_state.rs +++ b/gmod/src/lua/lua_state.rs @@ -392,7 +392,16 @@ impl LuaState { unreachable!() } - pub unsafe fn debug_get_info(&self, what: LuaString) -> Option { + 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 { let mut ar = MaybeUninit::uninit(); if (LUA_SHARED.lua_getinfo)(*self, what, ar.as_mut_ptr()) != 0 { Some(ar.assume_init()) @@ -401,7 +410,16 @@ impl LuaState { } } - pub unsafe fn debug_get_invocation_info(&self, level: i32, what: LuaString) -> Option { + pub unsafe fn get_stack_at(&self, level: i32) -> Option { + 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 { let mut ar = MaybeUninit::uninit(); if (LUA_SHARED.lua_getstack)(*self, level, ar.as_mut_ptr()) != 0 { if (LUA_SHARED.lua_getinfo)(*self, what, ar.as_mut_ptr()) != 0 {