foxygit / fake-08-xbox360 Log in
commit d639e8d4770ce3af9ba8d87bc84fc813f5a49f15
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Jan 17 20:29:22 2026 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Jan 17 20:29:22 2026 -0700

    update z8 lua with fix for nested short if and add tests
---
 libs/z8lua              |  2 +-
 test/customLuaTests.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/libs/z8lua b/libs/z8lua
index 01c9caa..531d46c 160000
--- a/libs/z8lua
+++ b/libs/z8lua
@@ -1 +1 @@
-Subproject commit 01c9caa205c43c55753d6ceab56460064b16efc3
+Subproject commit 531d46c6bf11abd0ebec8ed42330f4a0628afac2
diff --git a/test/customLuaTests.cpp b/test/customLuaTests.cpp
index 2bd79f4..f729e6e 100644
--- a/test/customLuaTests.cpp
+++ b/test/customLuaTests.cpp
@@ -322,4 +322,78 @@ TEST_CASE("Alternative not equal (!=)") {
     }

     lua_close(L);
-}
\ No newline at end of file
+}
+TEST_CASE("Nested Shorthand IF logic") {
+    lua_State *L = luaL_newstate();
+    luaL_openlibs(L);
+
+    SUBCASE("shorthand if with shortprint swallowing next line") {
+        const char* code =
+        "res=0 c=2\n"
+        "if c==1 then\n"
+        "  if (1==1) ? 'test'\n"
+        "elseif c==2 then\n"
+        "  res=2\n"
+        "end\n"
+        "return res";
+        int result = luaL_dostring(L, code);
+        CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+        if (result == LUA_OK) {
+            // Prior to a bug fix in lparser.c, the 'elseif' is swallowed by the inner 'if',
+            // resulting in res remaining 0.
+            CHECK_EQ(lua_tointeger(L, -1), 2);
+        }
+    }
+
+    SUBCASE("shorthand if with else on same line") {
+        const char* code =
+        "if (1==0) return 1 else return 2";
+        int result = luaL_dostring(L, code);
+        CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+        if (result == LUA_OK) {
+            CHECK_EQ(lua_tointeger(L, -1), 2);
+        }
+    }
+
+    SUBCASE("shorthand if nested with outer else if (same line recursion)") {
+        const char* code =
+        "res=0 if(1==0) res=1 else if(1==1) res=2\n"
+        "return res";
+        int result = luaL_dostring(L, code);
+        CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+        if (result == LUA_OK) {
+            CHECK_EQ(lua_tointeger(L, -1), 2);
+        }
+    }
+
+    lua_close(L);
+}
+
+TEST_CASE("Shorthand IF braces logic") {
+    lua_State *L = luaL_newstate();
+    luaL_openlibs(L);
+
+    SUBCASE("shorthand if with braces") {
+        const char* code =
+        "x=0 if (1==1) x=1\n"
+        "return x";
+        int result = luaL_dostring(L, code);
+        CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+        if (result == LUA_OK) {
+            CHECK_EQ(lua_tointeger(L, -1), 1);
+        }
+    }
+
+    SUBCASE("shorthand if without braces") {
+        const char* code =
+        "x=0 if 1==1 x=1\n"
+        "return x";
+        int result = luaL_dostring(L, code);
+        CHECK_MESSAGE(result == LUA_OK, lua_tostring(L, -1));
+        if (result == LUA_OK) {
+            CHECK_EQ(lua_tointeger(L, -1), 1);
+        }
+    }
+
+    lua_close(L);
+}