From a5e84a44ec6041ee5067b88c4c7b16f85475ec90 Mon Sep 17 00:00:00 2001 From: Titanium Brain Date: Sat, 11 Jul 2026 12:04:17 +0100 Subject: [PATCH] feat(zlua): unify zlua dependency Moves zlua to ly-core. Uses only LuaJIT for everything. Switches some methods to those available in LuaJIT. --- build.zig | 7 ------- ly-core/build.zig | 2 +- ly-core/src/root.zig | 30 ++++++++++++++++++------------ src/animations/Lua.zig | 2 +- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/build.zig b/build.zig index cdb0d1f..5f88ccb 100644 --- a/build.zig +++ b/build.zig @@ -102,13 +102,6 @@ pub fn build(b: *std.Build) !void { }), }); - const zlua = b.dependency("zlua", .{ - .target = target, - .optimize = optimize, - .lang = .luajit, - }); - exe.root_module.addImport("zlua", zlua.module("zlua")); - const ly_ui = b.dependency("ly_ui", .{ .target = target, .optimize = optimize, diff --git a/ly-core/build.zig b/ly-core/build.zig index 2dd9725..37b8668 100644 --- a/ly-core/build.zig +++ b/ly-core/build.zig @@ -24,7 +24,7 @@ pub fn build(b: *std.Build) void { const zlua = b.dependency("zlua", .{ .target = target, .optimize = optimize, - .lang = .lua53, + .lang = .luajit, }); mod.addImport("zlua", zlua.module("zlua")); diff --git a/ly-core/src/root.zig b/ly-core/src/root.zig index 3ca6c49..7c1322a 100644 --- a/ly-core/src/root.zig +++ b/ly-core/src/root.zig @@ -208,13 +208,17 @@ pub fn LuaParser(comptime Struct: type) type { } const actual_type_info = @typeInfo(actual_type); - errdefer |err| errorHandler(@typeName(field.type), field.name, lua.toStringEx(-1), err); + errdefer |err| { + const value = lua.toString(-1) catch ""; + const duped = allocator.dupe(u8, value) catch ""; + errorHandler(@typeName(field.type), field.name, duped, err); + } // dispatch depending on type if (actual_type_info == .int and is_optional) { - if (lua.isInteger(-1)) { - const value = try lua.toInteger(-1); - @field(data, field.name) = @intCast(value); + if (lua.isNumber(-1)) { + const value = try lua.toNumber(-1); + @field(data, field.name) = @trunc(value); } else { const str = try lua.toString(-1); @@ -229,9 +233,9 @@ pub fn LuaParser(comptime Struct: type) type { } // non null integer } else if (actual_type_info == .int) { - if (lua.isInteger(-1)) { - const value = try lua.toInteger(-1); - @field(data, field.name) = @intCast(value); + if (lua.isNumber(-1)) { + const value = try lua.toNumber(-1); + @field(data, field.name) = @trunc(value); } else { const str = try lua.toString(-1); @@ -275,12 +279,13 @@ pub fn LuaParser(comptime Struct: type) type { // custom_commands can be omitted or empty, so we just skip instead of erroring if (lua.isTable(-1)) binds: { - const len: usize = @intCast(lua.lenRaiseErr(-1)); + const len: usize = @intCast(lua.objectLen(-1)); if (len == 0) break :binds; for (1..len + 1) |i| { // push i-th table to stack - const ith_table_type = lua.getIndex(-1, @intCast(i)); + lua.pushInteger(@intCast(i)); + const ith_table_type = lua.getTable(-2); defer lua.pop(1); // i-th table in custom_commands if (ith_table_type != .table) continue; @@ -289,6 +294,7 @@ pub fn LuaParser(comptime Struct: type) type { if (binding_type != .string) continue; const binding = lua.toString(-1) catch continue; const bindingZ = temporary_allocator.dupe(u8, binding) catch ""; + std.debug.print("{s}", .{bindingZ}); lua.pop(1); // binding value if (!custom.binds.contains(bindingZ)) { @@ -311,19 +317,19 @@ pub fn LuaParser(comptime Struct: type) type { } } } - lua.pop(1); _ = lua.getField(-1, "custom_labels"); // custom_labels can be omitted, so we just skip instead of erroring if (lua.isTable(-1)) labels: { - const len: usize = @intCast(lua.lenRaiseErr(-1)); + const len: usize = @intCast(lua.objectLen(-1)); if (len == 0) break :labels; for (1..len + 1) |i| { // push i-th table to stack - const ith_table_type = lua.getIndex(-1, @intCast(i)); + lua.pushInteger(@intCast(i)); + const ith_table_type = lua.getTable(-2); defer lua.pop(1); // i-th table in custom_labels if (ith_table_type != .table) continue; diff --git a/src/animations/Lua.zig b/src/animations/Lua.zig index 2d2956f..bb4d406 100644 --- a/src/animations/Lua.zig +++ b/src/animations/Lua.zig @@ -8,7 +8,7 @@ const Allocator = std.mem.Allocator; const InfoLine = @import("../components/InfoLine.zig"); const Lang = @import("../config/Lang.zig"); -const zlua = @import("zlua"); +const zlua = ly_ui.ly_core.zlua; const ly_lua = @embedFile("ly.lua");