Skip to content

Commit 3406221

Browse files
authored
Fix checkArgument logical error (#18)
1 parent bf912f6 commit 3406221

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [2.0.0] - 2025-05-21
9+
10+
### Fixed
11+
12+
- Corrected a logic error causing the `Lua.checkArgument()` function to incorrectly error on a passing condition.
13+
- Refer to [bug: checkArgument has inverse logic #17](https://github.com/sackosoft/zig-luajit/issues/17)
14+
15+
[2.0.0]: https://github.com/sackosoft/zig-luajit/compare/v1.5.4...v2.0.0
16+
[1.5.4]: https://github.com/sackosoft/zig-luajit/releases/tag/v2.0.0

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.{
22
.name = .luajit,
33
.fingerprint = 0xda4bba66d285c19c,
4-
.version = "1.5.4",
4+
.version = "2.0.0",
55
.dependencies = .{
66
.luajit_build = .{
77
.url = "git+https://github.com/sackosoft/zig-luajit-build#d75c20acaa4df39f51187926fa9d98e4e5231064",

src/root.zig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,8 +2352,9 @@ pub const Lua = opaque {
23522352
/// Refer to: https://www.lua.org/manual/5.1/manual.html#luaL_argcheck
23532353
/// Stack Behavior: `[-0, +0, v]`
23542354
pub fn checkArgument(lua: *Lua, condition: bool, arg_n: i32, extra_message: ?[:0]const u8) void {
2355-
if (condition) {
2355+
if (!condition) {
23562356
_ = c.luaL_argerror(asState(lua), arg_n, if (extra_message) |m| m else null);
2357+
unreachable;
23572358
}
23582359
}
23592360

@@ -4887,7 +4888,7 @@ test "checkArgument() should return error when argument is invalid and succeed w
48874888
const T = struct {
48884889
fn EchoInteger(l: *Lua) callconv(.c) i32 {
48894890
const val = l.toInteger(1);
4890-
l.checkArgument(val != 42, 1, "FOOBAR");
4891+
l.checkArgument(val == 42, 1, "FOOBAR");
48914892
l.pushInteger(val);
48924893
return 1;
48934894
}
@@ -4966,7 +4967,7 @@ test "checkArgument() should return handle null message" {
49664967
const T = struct {
49674968
fn EchoInteger(l: *Lua) callconv(.c) i32 {
49684969
const val = l.toInteger(1);
4969-
l.checkArgument(val != 42, 1, null);
4970+
l.checkArgument(val == 42, 1, null);
49704971
l.pushInteger(val);
49714972
return 1;
49724973
}

0 commit comments

Comments
 (0)