Skip to content

Fix build break for zig 0.14.0-dev.2596 #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/configure-pages@v2
- uses: mlugg/setup-zig@v1
with:
version: 0.14.0-dev.1820+ea527f7a8
version: 0.14.0-dev.2851+b074fb7dd
- run: make docs
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: 0.14.0-dev.1820+ea527f7a8
version: 0.14.0-dev.2851+b074fb7dd

- name: Run tests
run: make test
6 changes: 4 additions & 2 deletions build/luajit.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
.name = "lua",
.target = target,
.optimize = optimize,
.unwind_tables = .sync,
})
else
b.addStaticLibrary(.{
.name = "lua",
.target = target,
.optimize = optimize,
.unwind_tables = .sync,
});

// Compile minilua interpreter used at build time to generate files
Expand Down Expand Up @@ -163,9 +165,9 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.

lib.linkLibC();

lib.defineCMacro("LUAJIT_UNWIND_EXTERNAL", null);
lib.root_module.addCMacro("LUAJIT_UNWIND_EXTERNAL", "");

lib.linkSystemLibrary("unwind");
lib.root_module.unwind_tables = true;

lib.addIncludePath(upstream.path("src"));
lib.addIncludePath(luajit_h.dirname());
Expand Down
8 changes: 4 additions & 4 deletions src/define.zig
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn addClass(
try state.definitions.items[index].appendSlice("---@field ");
try state.definitions.items[index].appendSlice(field.name);

if (field.default_value != null) {
if (field.defaultValue() != null) {
try state.definitions.items[index].appendSlice("?");
}
try state.definitions.items[index].appendSlice(" ");
Expand All @@ -123,13 +123,13 @@ fn luaTypeName(
try addClass(state, T);
},
.pointer => |info| {
if (info.child == u8 and info.size == .Slice) {
if (info.child == u8 and info.size == .slice) {
try state.definitions.items[index].appendSlice("string");
} else switch (info.size) {
.One => {
.one => {
try state.definitions.items[index].appendSlice("lightuserdata");
},
.C, .Many, .Slice => {
.c, .many, .slice => {
try luaTypeName(state, index, info.child);
try state.definitions.items[index].appendSlice("[]");
},
Expand Down
36 changes: 18 additions & 18 deletions src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4311,9 +4311,9 @@ pub const Lua = opaque {
/// Returns if given typeinfo is a string type
fn isTypeString(typeinfo: std.builtin.Type.Pointer) bool {
const childinfo = @typeInfo(typeinfo.child);
if (typeinfo.child == u8 and typeinfo.size != .One) {
if (typeinfo.child == u8 and typeinfo.size != .one) {
return true;
} else if (typeinfo.size == .One and childinfo == .array and childinfo.array.child == u8) {
} else if (typeinfo.size == .one and childinfo == .array and childinfo.array.child == u8) {
return true;
}
return false;
Expand All @@ -4323,22 +4323,22 @@ pub const Lua = opaque {
fn pushAnyString(lua: *Lua, value: anytype) !void {
const info = @typeInfo(@TypeOf(value)).pointer;
switch (info.size) {
.One => {
.one => {
const childinfo = @typeInfo(info.child).array;
std.debug.assert(childinfo.child == u8);
std.debug.assert(childinfo.sentinel != null);
std.debug.assert(childinfo.sentinel() != null);

const casted: *childinfo.child = @ptrCast(@constCast(childinfo.sentinel.?));
if (casted.* != 0) {
@compileError("Sentinel of slice must be a null terminator");
if (childinfo.sentinel()) |sentinel| {
if (sentinel != 0) {
@compileError("Sentinel of slice must be a null terminator");
}
}
_ = lua.pushStringZ(value);
},
.C, .Many, .Slice => {
.c, .many, .slice => {
std.debug.assert(info.child == u8);
if (info.sentinel) |sentinel| {
const casted: *info.child = @ptrCast(@constCast(sentinel));
if (casted.* != 0) {
if (info.sentinel()) |sentinel| {
if (sentinel != 0) {
@compileError("Sentinel of slice must be a null terminator");
}
_ = lua.pushStringZ(value);
Expand Down Expand Up @@ -4366,15 +4366,15 @@ pub const Lua = opaque {
if (comptime isTypeString(info)) {
try lua.pushAnyString(value);
} else switch (info.size) {
.One => {
.one => {
if (info.is_const) {
@compileLog(value);
@compileLog("Lua cannot guarantee that references will not be modified");
@compileError("Pointer must not be const");
}
lua.pushLightUserdata(@ptrCast(value));
},
.C, .Many, .Slice => {
.c, .many, .slice => {
lua.createTable(0, 0);
for (value, 0..) |index_value, i| {
try lua.pushAny(i + 1);
Expand Down Expand Up @@ -4521,16 +4521,16 @@ pub const Lua = opaque {
@compileError("toAny cannot allocate memory, try using toAnyAlloc");
}

if (info.sentinel != null) {
if (info.sentinel() != null) {
return try a.?.dupeZ(u8, string[0..end]);
} else {
return try a.?.dupe(u8, string[0..end]);
}
} else {
return if (info.sentinel == null) string[0..end] else string[0..end :0];
return if (info.sentinel() == null) string[0..end] else string[0..end :0];
}
} else switch (info.size) {
.Slice, .Many => {
.slice, .many => {
if (!allow_alloc) {
@compileError("toAny cannot allocate memory, try using toAnyAlloc");
}
Expand Down Expand Up @@ -4641,8 +4641,8 @@ pub const Lua = opaque {
const lua_field_type = lua.getTable(index);
defer lua.pop(1);
if (lua_field_type == .nil) {
if (field.default_value) |default_value| {
@field(result, field.name) = @as(*const field.type, @ptrCast(@alignCast(default_value))).*;
if (field.defaultValue()) |default| {
@field(result, field.name) = default;
} else if (field_type_info != .optional) {
return error.LuaTableMissingValue;
}
Expand Down
14 changes: 14 additions & 0 deletions src/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,20 @@ test "pushAny struct" {
try testing.expect(value.bar == (MyType{}).bar);
}

test "pushAny anon struct" {
var lua = try Lua.init(testing.allocator);
defer lua.deinit();

const MyType = struct {
x: i32,
enable: bool,
};
try lua.pushAny(.{ .x = @as(i32, 13), .enable = true });
const value = try lua.toAny(MyType, -1);
try testing.expect(value.x == 13);
try testing.expect(value.enable == true);
}

test "pushAny tagged union" {
var lua = try Lua.init(testing.allocator);
defer lua.deinit();
Expand Down
Loading