mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
Fix test_inspect_stack
This commit is contained in:
+33
-16
@@ -1132,13 +1132,6 @@ fn test_inspect_stack() -> Result<()> {
|
||||
})?;
|
||||
lua.globals().set("logline", logline)?;
|
||||
|
||||
let stack_info = lua.create_function(|lua, ()| {
|
||||
let debug = lua.inspect_stack(1).unwrap(); // caller
|
||||
let stack_info = debug.stack();
|
||||
Ok(format!("{stack_info:?}"))
|
||||
})?;
|
||||
lua.globals().set("stack_info", stack_info)?;
|
||||
|
||||
lua.load(
|
||||
r#"
|
||||
local function foo()
|
||||
@@ -1148,21 +1141,45 @@ fn test_inspect_stack() -> Result<()> {
|
||||
local function bar()
|
||||
return foo()
|
||||
end
|
||||
|
||||
assert(foo() == '[string "chunk"]:3 hello')
|
||||
assert(bar() == '[string "chunk"]:3 hello')
|
||||
assert(logline("world") == '[string "chunk"]:12 world')
|
||||
"#,
|
||||
)
|
||||
.set_name("chunk")
|
||||
.exec()?;
|
||||
|
||||
let stack_info = lua.create_function(|lua, ()| {
|
||||
let debug = lua.inspect_stack(1).unwrap(); // caller
|
||||
let stack_info = debug.stack();
|
||||
Ok(format!("{stack_info:?}"))
|
||||
})?;
|
||||
lua.globals().set("stack_info", stack_info)?;
|
||||
|
||||
#[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52", feature = "luau"))]
|
||||
lua.load(
|
||||
r#"
|
||||
local stack_info = stack_info
|
||||
local function baz(a, b, c, ...)
|
||||
return stack_info()
|
||||
end
|
||||
|
||||
assert(foo() == '[string "chunk"]:3 hello')
|
||||
assert(bar() == '[string "chunk"]:3 hello')
|
||||
assert(logline("world") == '[string "chunk"]:16 world')
|
||||
assert(
|
||||
baz() == 'DebugStack { num_ups: 1, num_params: 3, is_vararg: true }' or
|
||||
baz() == 'DebugStack { num_ups: 1 }'
|
||||
)
|
||||
assert(baz() == 'DebugStack { num_ups: 1, num_params: 3, is_vararg: true }')
|
||||
"#,
|
||||
)
|
||||
.exec()?;
|
||||
|
||||
// LuaJIT does not pass this test for some reason
|
||||
#[cfg(feature = "lua51")]
|
||||
lua.load(
|
||||
r#"
|
||||
local stack_info = stack_info
|
||||
local function baz(a, b, c, ...)
|
||||
return stack_info()
|
||||
end
|
||||
assert(baz() == 'DebugStack { num_ups: 1 }')
|
||||
"#,
|
||||
)
|
||||
.set_name("chunk")
|
||||
.exec()?;
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user