Add Lua 5.5 support and fix Zig 0.16 compatibility#193
Merged
robbielyman merged 12 commits intonatecraddock:mainfrom Jan 30, 2026
Merged
Add Lua 5.5 support and fix Zig 0.16 compatibility#193robbielyman merged 12 commits intonatecraddock:mainfrom
robbielyman merged 12 commits intonatecraddock:mainfrom
Conversation
- Add lua55 dependency to build.zig.zon (lua-5.5.0.tar.gz) - Add lua55 variant to Language enum in build/lua.zig - Add lua55 source files list (same structure as 5.4) - Update build.zig to handle lua55 system library linking API changes for Lua 5.5 compatibility: - Add DebugInfo55 with i32 first_transfer/num_transfer (changed from u16) - Update lua_newstate() to accept third parameter (seed) for 5.5 - Add null buffer check in CWriterFn wrap (Lua 5.5 calls writer with null at end) - Update all version switches to include .lua55 - Fix @ptrCast type inference in openLibs() Test updates: - Add version check for Lua 5.5 (505) - Update resumeThread calls for 5.4/5.5 (requires num_results parameter) - Update userdata tests to handle 5.5 user_values API - Skip dump/load test for 5.5 (format changed) - Update GC, compare, and concat tests for 5.5 behavior All tests pass for lua52, lua53, lua54, and lua55.
- Replace deprecated std.process.argsAlloc with std.process.Init.Minimal - Update main() signature to use std.process.Init.Minimal parameter - Use init.args.iterate() instead of argsAlloc for command line parsing This fixes the build for Lua 5.1 which uses the patch tool to apply CVE-2014-5461 security fix to ldo.c.
Remove the separate code path for Lua 5.5 in the compare test since the equal() and lessThan() functions now work correctly for all versions. This reduces code duplication and makes the test more maintainable.
The root cause was that LuaJIT was unconditionally compiled with external unwind mode (LUAJIT_UNWIND_EXTERNAL), which requires all frames in the call chain to have proper unwind info. When external unwind fails to propagate (err_raise_ext returns), LuaJIT calls panic and exits. Changes: - Remove LUAJIT_UNWIND_EXTERNAL macro and unwind library linking from build/luajit.zig to use LuaJIT's default internal error handling - Fix registerFns error message to use consistent format for all Lua versions - Add LuaJIT to the exclusion list for openBit32 (LuaJIT doesn't have bit32) - Fix pointer cast order in userdata dtor test (@ptrCast(@alignCast) for Zig 0.16 compatibility) All tests now pass.
Remove the LJ_NO_UNWIND=1 workaround for Darwin now that the Zig compiler bug (https://codeberg.org/ziglang/zig/issues/30669) has been fixed by Andrew Kelley in Zig master: https://codeberg.org/ziglang/zig/commit/63f345a75afdf4f956b136c06776f109f5c567af The bug caused stack check to be incorrectly enabled for external unwind, which made err_raise_ext fail and return instead of properly unwinding.
Refactor openBit32 to use explicit switch statement for clarity: - Lua 5.2: use luaopen_bit32 - LuaJIT: use luaopen_bit (LuaJIT's bit library) - Other versions: no-op (they don't have bit32) Also simplify the test condition to explicitly check for lua52 and luajit instead of excluding multiple versions.
Previously removed the LUA_QS branch in registerFns to work around a c-translate error on Zig nightly. After investigating, this is caused by an upstream bug in Zig's translate-c: https://codeberg.org/ziglang/translate-c/issues/282 The bug affects LUA_QL macro parsing, which breaks LUA_QS (as it expands to LUA_QL). Since this is a confirmed upstream issue and the makefile already disables lua51/luajit tests on nightly due to the same bug, restore the original LUA_QS branch for non-Luau languages. Changes: - Restore LUA_QS usage for lua51-lua54 and luajit in registerFns - Add lua55 test target to test_zig_nightly and test_zig_stable
- Remove skip for Lua 5.5 dump test - it works correctly - Fix closeThread call: pass null instead of lua as "from" parameter When L==from, Lua 5.5 treats this as "thread closing itself" which only works inside a resume. Pass null to reset thread normally. See: https://www.lua.org/manual/5.5/manual.html#lua_closethread
The yielding test has an early return for non-5.3/5.4/5.5 versions, so the else block handling Lua 5.1/LuaJIT was unreachable code. - Change "else if (lua52 or lua53)" to "else" since only 5.3 remains - Remove dead code for 5.1/LuaJIT that could never execute
- gc test: include lua55 in gcSetGenerational check - userdata test: include lua55 in setUserValue/getUserValue check - resuming test: remove lua54 skip, refactor to use switch for clarity
Include lua55 in the upvalueId error test case (same behavior as lua54).
robbielyman
approved these changes
Jan 30, 2026
Collaborator
robbielyman
left a comment
There was a problem hiding this comment.
Thanks very much! I'm going to go ahead and make the openBit change I suggested.
src/lib.zig
Outdated
| lua.requireF(c.LUA_BITLIBNAME, c.luaopen_bit32, true); | ||
| if (lang == .lua52 or lang == .lua53 or lang == .lua54) lua.pop(1); | ||
| switch (lang) { | ||
| .lua52 => lua.requireF(c.LUA_BITLIBNAME, c.luaopen_bit32, true), |
Collaborator
There was a problem hiding this comment.
Since the library is available in Lua 5.3, probably we should require it if the user asks for it. Maybe the openBit32 function should instead be named openBit and use the indicated functions for lua 5.2, 5.3 and luajit, and otherwise be a compile error?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for the latest Lua 5.5 release and improves Zig 0.16 nightly compatibility(0.16.0-dev.2349+204fa8959).
Lua 5.5 Support
lua_newstatesignature - Lua 5.5 adds a newmisizeparameter for minimum stack size; handle with conditional compilationDebugInfo55structure - New debug interface withprivatefield for internal state.lua55to all relevant version switches:ArithOperator,Event,DebugInfo,dump,equal,gc*functionsStream,StreamFn,yieldContcontinuation signaturesopenCoro,openUtf8library loadersldo.c,lctype.c,lcorolib.c,lutf8lib.cin buildlua5.5system library when usinguse_system_luaZig 0.16 Nightly Compatibility
build/patch.zigentry point - Update from legacypub fn main() !voidto newpub fn main(init: std.process.Init.Minimal) !voidsignaturestd.process.argsAllocwith iterator-basedinit.args.iterate()API@ptrCastusage for stricter Zig 0.16 type checking in various FFI callsLuaJIT Fixes
LJ_NO_UNWIND=1workaround now that the Zig compiler bug (ziglang/zig#30669) has been fixed in master by AndrewBit Library Improvements
Note: This is a bit of a hack to resolve immediate symbol errors. LuaJIT's
bitlibrary and Lua 5.2'sbit32have behavioral differences (different module names, slightly different APIs). A more elegant solution might be to expose them as separate functions or handle the differences at the API level rather than conflating them inopenBit32.luaopen_bit32luaopen_bit(LuaJIT's bit library)Files Changed
build.zig- Update version handlingbuild.zig.zon- Add Lua 5.5 package referencebuild/lua.zig- Add Lua 5.5 build configurationbuild/luajit.zig- Remove Darwin unwind workaround, restore external unwindbuild/patch.zig- Fix Zig 0.16 pointer cast syntaxsrc/lib.zig- Add Lua 5.5 compatibility, fix error messages and pointer casts, improve bit library handlingsrc/tests.zig- Fix tests for LuaJIT and Zig 0.16 compatibility, simplify bit32 test conditionsreadme.md- Update documentation