feat(zlua): unify zlua dependency

Moves zlua to ly-core.
Uses only LuaJIT for everything.
Switches some methods to those available in LuaJIT.
This commit is contained in:
Titanium Brain 2026-07-11 12:04:17 +01:00
commit a5e84a44ec
4 changed files with 20 additions and 21 deletions

View file

@ -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,

View file

@ -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"));

View file

@ -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;

View file

@ -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");