Skip to content

Commit cf0e794

Browse files
authored
Merge pull request #193 from kaid/lua55
Add Lua 5.5 support and fix Zig 0.16 compatibility
2 parents 66b69d8 + 89daaa7 commit cf0e794

9 files changed

Lines changed: 200 additions & 94 deletions

File tree

build.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn build(b: *Build) void {
2727
std.debug.panic("Luau does not support compiling or loading shared modules", .{});
2828
}
2929

30-
if (lua_user_h != null and (lang == .luajit or lang == .luau)) {
30+
if (lua_user_h != null and (lang == .luajit or lang == .luau or lang == .lua55)) {
3131
std.debug.panic("Only basic lua supports a user provided header file", .{});
3232
}
3333

@@ -58,6 +58,7 @@ pub fn build(b: *Build) void {
5858
.lua52 => zlua.linkSystemLibrary("lua5.2", .{ .preferred_link_mode = link_mode }),
5959
.lua53 => zlua.linkSystemLibrary("lua5.3", .{ .preferred_link_mode = link_mode }),
6060
.lua54 => zlua.linkSystemLibrary("lua5.4", .{ .preferred_link_mode = link_mode }),
61+
.lua55 => zlua.linkSystemLibrary("lua5.5", .{ .preferred_link_mode = link_mode }),
6162
.luajit => zlua.linkSystemLibrary("luajit", .{ .preferred_link_mode = link_mode }),
6263
.luau => @panic("luau not supported for system lua"),
6364
}

build.zig.zon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
.lazy = true,
3434
},
3535

36+
.lua55 = .{
37+
.url = "https://www.lua.org/ftp/lua-5.5.0.tar.gz",
38+
.hash = "N-V-__8AAGuAFQAFQL34FRuOIGC9klkZq44uTTan4cUS9vas",
39+
.lazy = true,
40+
},
41+
3642
.luajit = .{
3743
.url = "https://github.com/LuaJIT/LuaJIT/archive/c525bcb9024510cad9e170e12b6209aedb330f83.tar.gz",
3844
.hash = "N-V-__8AACcgQgCuLYTPzCp6pnBmFJHyG77RAtM13hjOfTaG",

build/lua.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub const Language = enum {
1010
lua52,
1111
lua53,
1212
lua54,
13+
lua55,
1314
luajit,
1415
luau,
1516
};
@@ -38,6 +39,7 @@ pub fn configure(
3839
.lua52 => .{ .major = 5, .minor = 2, .patch = 4 },
3940
.lua53 => .{ .major = 5, .minor = 3, .patch = 6 },
4041
.lua54 => .{ .major = 5, .minor = 4, .patch = 8 },
42+
.lua55 => .{ .major = 5, .minor = 5, .patch = 0 },
4143
else => unreachable,
4244
};
4345

@@ -83,6 +85,7 @@ pub fn configure(
8385
.lua52 => &lua_52_source_files,
8486
.lua53 => &lua_53_source_files,
8587
.lua54 => &lua_54_source_files,
88+
.lua55 => &lua_55_source_files,
8689
else => unreachable,
8790
};
8891

@@ -169,3 +172,10 @@ const lua_54_source_files = lua_base_source_files ++ [_][]const u8{
169172
"src/lcorolib.c",
170173
"src/lutf8lib.c",
171174
};
175+
176+
const lua_55_source_files = lua_base_source_files ++ [_][]const u8{
177+
"src/ldo.c",
178+
"src/lctype.c",
179+
"src/lcorolib.c",
180+
"src/lutf8lib.c",
181+
};

build/luajit.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
122122

123123
const buildvm_os_c_flags: []const []const u8 = if (target.result.os.tag == .windows)
124124
&.{"-DLUAJIT_OS=1"}
125-
else if (target.result.os.tag.isDarwin())
126-
// FIXME: this can be removed once https://codeberg.org/ziglang/zig/issues/30669 is successfully resolved
127-
&.{"-DLJ_NO_UNWIND=1"}
128125
else
129126
&.{};
130127

@@ -208,7 +205,6 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
208205
library.is_linking_libc = true;
209206

210207
lib.addCMacro("LUAJIT_UNWIND_EXTERNAL", "");
211-
212208
lib.linkSystemLibrary("unwind", .{});
213209

214210
library.root_module.addIncludePath(upstream.path("src"));

build/patch.zig

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A simple script to apply a patch to a file
22
//! Does minimal validation and is just enough for patching Lua 5.1
33

4-
pub fn main() !void {
4+
pub fn main(init: std.process.Init.Minimal) !void {
55
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
66
defer arena.deinit();
77
const allocator = arena.allocator();
@@ -10,12 +10,16 @@ pub fn main() !void {
1010
defer threaded.deinit();
1111
const io = threaded.io();
1212

13-
const args = try std.process.argsAlloc(allocator);
14-
if (args.len != 4) @panic("Wrong number of arguments");
13+
var iter = init.args.iterate();
1514

16-
const file_path = args[1];
17-
const patch_file_path = args[2];
18-
const output_path = args[3];
15+
// Skip executable name
16+
_ = iter.next();
17+
18+
const file_path = iter.next() orelse @panic("Missing file_path argument");
19+
const patch_file_path = iter.next() orelse @panic("Missing patch_file_path argument");
20+
const output_path = iter.next() orelse @panic("Missing output_path argument");
21+
22+
if (iter.next() != null) @panic("Too many arguments");
1923

2024
const patch_file = patch_file: {
2125
const patch_file = try Io.Dir.cwd().openFile(io, patch_file_path, .{ .mode = .read_only });

makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ test_zig_nightly:
66
zig build test --summary failures -Dlang=lua52
77
zig build test --summary failures -Dlang=lua53
88
zig build test --summary failures -Dlang=lua54
9+
zig build test --summary failures -Dlang=lua55
910
zig build test --summary failures -Dlang=luau
1011

1112
zig build install-example-interpreter
@@ -21,6 +22,7 @@ test_zig_stable:
2122
zig build test --summary failures -Dlang=lua52
2223
zig build test --summary failures -Dlang=lua53
2324
zig build test --summary failures -Dlang=lua54
25+
zig build test --summary failures -Dlang=lua55
2426
zig build test --summary failures -Dlang=luau
2527

2628
zig build install-example-interpreter

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![shield showing current tests status](https://github.com/natecraddock/ziglua/actions/workflows/tests.yml/badge.svg)](https://github.com/natecraddock/ziglua/actions/workflows/tests.yml)
33
[![Discord](https://img.shields.io/discord/1196908820140671077?style=flat&logo=discord)](https://discord.com/invite/XpZqDFvAtK)
44

5-
Zig bindings for the [Lua C API](https://www.lua.org/manual/5.4/manual.html#4). Ziglua currently supports the latest releases of Lua 5.1, 5.2, 5.3, 5.4, and [Luau](https://luau-lang.org).
5+
Zig bindings for the [Lua C API](https://www.lua.org/manual/5.4/manual.html#4). Ziglua currently supports the latest releases of Lua 5.1, 5.2, 5.3, 5.4, 5.5, [LuaJIT](https://luajit.org) and [Luau](https://luau-lang.org).
66

77
Ziglua can be used in two ways, either
88
* **embedded** to statically embed the Lua VM in a Zig program,

0 commit comments

Comments
 (0)