diff --git a/src/ziglua-5.1/lib.zig b/src/ziglua-5.1/lib.zig index dab22a7..70f8ee3 100644 --- a/src/ziglua-5.1/lib.zig +++ b/src/ziglua-5.1/lib.zig @@ -387,6 +387,13 @@ pub const Lua = struct { if (c.lua_dump(lua.state, writer, data) != 0) return error.Fail; } + /// Returns true if the two values at the indexes are equal following the semantics of the + /// Lua == operator. + /// See https://www.lua.org/manual/5.1/manual.html#lua_equal + pub fn equal(lua: *Lua, index1: i32, index2: i32) bool { + return c.lua_equal(lua.state, index1, index2) == 1; + } + /// Raises a Lua error using the value at the top of the stack as the error object /// Does a longjump and therefore never returns /// See https://www.lua.org/manual/5.4/manual.html#lua_error @@ -573,6 +580,12 @@ pub const Lua = struct { return c.lua_isuserdata(lua.state, index) != 0; } + /// Returns true if the value at index1 is smaller than the value at index2, following the + /// semantics of the Lua < operator. + pub fn lessThan(lua: *Lua, index1: i32, index2: i32) bool { + return c.lua_lessthan(lua.state, index1, index2) == 1; + } + /// Loads a Lua chunk without running it /// If there are no errors, pushes the compiled chunk on the top of the stack as a function /// See https://www.lua.org/manual/5.4/manual.html#lua_load diff --git a/src/ziglua-5.1/tests.zig b/src/ziglua-5.1/tests.zig index 89b61de..c779186 100644 --- a/src/ziglua-5.1/tests.zig +++ b/src/ziglua-5.1/tests.zig @@ -281,6 +281,21 @@ test "filling and checking the stack" { try expectEqual(@as(i32, 40), lua.getTop()); } +test "comparisions" { + var lua = try Lua.init(testing.allocator); + defer lua.deinit(); + + lua.pushInteger(1); + lua.pushInteger(2); + + try testing.expect(!lua.equal(1, 2)); + try testing.expect(lua.lessThan(1, 2)); + + lua.pushInteger(2); + + try testing.expect(lua.equal(2, 3)); +} + test "stack manipulation" { var lua = try Lua.init(testing.allocator); defer lua.deinit();