Skip to content

Commit

Permalink
feat: add objectLen() to 5.1 api
Browse files Browse the repository at this point in the history
  • Loading branch information
natecraddock committed Feb 16, 2023
1 parent 458aced commit 53fc706
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ziglua-5.1/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,12 @@ pub const Lua = struct {
return c.lua_next(lua.state, index) != 0;
}

/// Returns the length of the value at the given index
/// See https://www.lua.org/manual/5.1/manual.html#lua_objlen
pub fn objectLen(lua: *Lua, index: i32) usize {
return c.lua_objlen(lua.state, index);
}

/// Calls a function (or callable object) in protected mode
/// NOTE: it might be good to make the args named struct params?
pub fn protectedCall(lua: *Lua, num_args: i32, num_results: i32, msg_handler: i32) !void {
Expand Down
8 changes: 8 additions & 0 deletions src/ziglua-5.1/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1148,3 +1148,11 @@ test "function environments" {
lua.getField(2, "x");
try testing.expectEqual(@as(Integer, 20), lua.toInteger(3));
}

test "objectLen" {
var lua = try Lua.init(testing.allocator);
defer lua.deinit();

lua.pushString("lua");
try testing.expectEqual(@as(usize, 3), lua.objectLen(-1));
}

0 comments on commit 53fc706

Please sign in to comment.