Skip to content

Commit a70d122

Browse files
committed
tests: add getStack test
This completes the debug library tests!
1 parent 99904a4 commit a70d122

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/tests.zig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,33 @@ test "debug upvalues" {
11011101
try expect((try lua.upvalueId(-2, 1)) == try lua.upvalueId(-1, 1));
11021102
}
11031103

1104+
test "getstack" {
1105+
var lua = try Lua.init(testing.allocator);
1106+
defer lua.deinit();
1107+
1108+
try expectError(Error.Fail, lua.getStack(1));
1109+
1110+
const function = struct {
1111+
fn inner(l: *Lua) i32 {
1112+
// get info about calling lua function
1113+
var info = l.getStack(1) catch unreachable;
1114+
l.getInfo(.{ .n = true }, &info);
1115+
expectEqualStrings("g", info.name.?) catch unreachable;
1116+
return 0;
1117+
}
1118+
}.inner;
1119+
1120+
lua.pushFunction(ziglua.wrap(function));
1121+
lua.setGlobal("f");
1122+
1123+
try lua.doString(
1124+
\\g = function()
1125+
\\ f()
1126+
\\end
1127+
\\g()
1128+
);
1129+
}
1130+
11041131
test "refs" {
11051132
// temporary test that includes a reference to all functions so
11061133
// they will be type-checked

0 commit comments

Comments
 (0)