Skip to content

Commit 53fc706

Browse files
committed
feat: add objectLen() to 5.1 api
1 parent 458aced commit 53fc706

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/ziglua-5.1/lib.zig

+6
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,12 @@ pub const Lua = struct {
647647
return c.lua_next(lua.state, index) != 0;
648648
}
649649

650+
/// Returns the length of the value at the given index
651+
/// See https://www.lua.org/manual/5.1/manual.html#lua_objlen
652+
pub fn objectLen(lua: *Lua, index: i32) usize {
653+
return c.lua_objlen(lua.state, index);
654+
}
655+
650656
/// Calls a function (or callable object) in protected mode
651657
/// NOTE: it might be good to make the args named struct params?
652658
pub fn protectedCall(lua: *Lua, num_args: i32, num_results: i32, msg_handler: i32) !void {

src/ziglua-5.1/tests.zig

+8
Original file line numberDiff line numberDiff line change
@@ -1148,3 +1148,11 @@ test "function environments" {
11481148
lua.getField(2, "x");
11491149
try testing.expectEqual(@as(Integer, 20), lua.toInteger(3));
11501150
}
1151+
1152+
test "objectLen" {
1153+
var lua = try Lua.init(testing.allocator);
1154+
defer lua.deinit();
1155+
1156+
lua.pushString("lua");
1157+
try testing.expectEqual(@as(usize, 3), lua.objectLen(-1));
1158+
}

0 commit comments

Comments
 (0)