diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2022-02-25 23:51:51 +0000 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2022-03-21 01:08:47 +0000 |
commit | 3e5f8e7bb8bb2822629593ecbd316f0fda7b4de8 (patch) | |
tree | a3c671bd43c804fdf5369cd1fb25bbc4139876c6 /src/lua.rs | |
parent | cab92f4ea2eb93d86a723384d6c08e0f16d16ad9 (diff) | |
download | mlua-3e5f8e7bb8bb2822629593ecbd316f0fda7b4de8.zip |
Enable `Lua::inspect_stack` for Luau
Diffstat (limited to 'src/lua.rs')
-rw-r--r-- | src/lua.rs | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -14,16 +14,15 @@ use rustc_hash::FxHashMap; use crate::error::{Error, Result}; use crate::ffi; use crate::function::Function; -#[cfg(not(feature = "luau"))] -use crate::hook::{Debug, HookTriggers}; +use crate::hook::Debug; use crate::scope::Scope; use crate::stdlib::StdLib; use crate::string::String; use crate::table::Table; use crate::thread::Thread; use crate::types::{ - Callback, CallbackUpvalue, DestructedUserdataMT, /*HookCallback,*/ Integer, LightUserData, - LuaRef, MaybeSend, Number, RegistryKey, + Callback, CallbackUpvalue, DestructedUserdataMT, Integer, LightUserData, LuaRef, MaybeSend, + Number, RegistryKey, }; use crate::userdata::{ AnyUserData, MetaMethod, UserData, UserDataCell, UserDataFields, UserDataMethods, @@ -36,9 +35,6 @@ use crate::util::{ }; use crate::value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti, Value}; -#[cfg(not(feature = "luau"))] -use crate::types::HookCallback; - #[cfg(not(feature = "lua54"))] use crate::util::push_userdata; #[cfg(feature = "lua54")] @@ -47,6 +43,9 @@ use { std::ffi::CStr, }; +#[cfg(not(feature = "luau"))] +use crate::{hook::HookTriggers, types::HookCallback}; + #[cfg(not(feature = "send"))] use std::rc::Rc; @@ -933,14 +932,19 @@ impl Lua { /// function that has called level `n` (except for tail calls, which do not count in the stack). /// /// [`Debug`]: crate::hook::Debug - #[cfg(not(feature = "luau"))] pub fn inspect_stack(&self, level: usize) -> Option<Debug> { unsafe { let mut ar: ffi::lua_Debug = mem::zeroed(); - if ffi::lua_getstack(self.state, level as c_int, &mut ar) == 0 { + let level = level as c_int; + #[cfg(not(feature = "luau"))] + if ffi::lua_getstack(self.state, level, &mut ar) == 0 { + return None; + } + #[cfg(feature = "luau")] + if ffi::lua_getinfo(self.state, level, cstr!(""), &mut ar) == 0 { return None; } - Some(Debug::new_owned(self, ar)) + Some(Debug::new_owned(self, level, ar)) } } |