diff --git a/lib/lua/build.zig b/lib/lua/build.zig index 066a9fd..dd757f7 100644 --- a/lib/lua/build.zig +++ b/lib/lua/build.zig @@ -12,17 +12,16 @@ pub fn build(b: *std.Build) void { .link_libc = true, }); - const luac = if (static_build) b.addStaticLibrary(.{ + const luac = b.addLibrary(.{ .name = "luac", - .target = target, - .optimize = optimize, - .link_libc = true, - }) else b.addSharedLibrary(.{ - .name = "luac", - .target = target, - .optimize = optimize, - .link_libc = true, + .linkage = if (static_build) .dynamic else .static, + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .link_libc = true, + }), }); + b.installArtifact(luac); luac.addCSourceFiles(.{ @@ -85,10 +84,12 @@ pub fn build(b: *std.Build) void { const run_step = b.step("test", ""); const tests = b.addExecutable(.{ .name = "run-lua", - .target = target, - .optimize = optimize, - .root_source_file = b.path("test/test-lua.zig"), - .link_libc = true, + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("test/test-lua.zig"), + .link_libc = true, + }), }); tests.root_module.addImport("lua", mod); diff --git a/lib/lua/src/lua.zig b/lib/lua/src/lua.zig index fe1db95..f33d27d 100644 --- a/lib/lua/src/lua.zig +++ b/lib/lua/src/lua.zig @@ -6,14 +6,14 @@ pub const LuaStateSettings = struct { defaultSetup: bool = true, }; -pub const LuaCFunc = *const fn (?*c.lua_State) callconv(.C) i32; +pub const LuaCFunc = *const fn (?*c.lua_State) callconv(.c) i32; pub const LuaZigFunc = *const fn (LuaState) i32; pub const LibSpec = []const c.luaL_Reg; pub const luaL_Reg = c.luaL_Reg; pub fn CWrap(comptime Func: anytype) LuaCFunc { const Wrap = struct { - pub fn inner(l: ?*c.lua_State) callconv(.C) i32 { + pub fn inner(l: ?*c.lua_State) callconv(.c) i32 { //return @call(.always_inline, Func, .{.{ .l = l }}); return Func(.{ .l = l }); } @@ -175,7 +175,7 @@ pub const LuaState = struct { pub fn pushFunction(self: @This(), comptime func: LuaZigFunc) !void { const Wrap = struct { - pub fn inner(l: ?*c.lua_State) callconv(.C) i32 { + pub fn inner(l: ?*c.lua_State) callconv(.c) i32 { return func(.{ .l = l }); } }; diff --git a/lib/lua/src/pod.zig b/lib/lua/src/pod.zig index 991b2c6..64e7d8e 100644 --- a/lib/lua/src/pod.zig +++ b/lib/lua/src/pod.zig @@ -119,13 +119,15 @@ pub fn Operator2Arg(comptime T: type, comptime Func: anytype) lua.LuaCFunc { } var Buffer: std.ArrayList(u8) = undefined; +var BufferAllocator: std.mem.Allocator = undefined; pub fn setupFormatBuffer(allocator: std.mem.Allocator) !void { - Buffer = std.ArrayList(u8).init(allocator); + Buffer = .{}; + BufferAllocator = allocator; } pub fn shutdownFormatBuffer() void { - Buffer.deinit(); + Buffer.deinit(BufferAllocator); } pub fn ToStringFunc(comptime T: type) lua.LuaCFunc { @@ -134,26 +136,25 @@ pub fn ToStringFunc(comptime T: type) lua.LuaCFunc { if (state.toUserdata(T, 1)) |value| { Buffer.clearRetainingCapacity(); - var writer = Buffer.writer(); - writer.print("{s}{{", .{T.PodDataTable.name}) catch return 0; + Buffer.print(BufferAllocator, "{s}{{", .{T.PodDataTable.name}) catch return 0; inline for (std.meta.fields(T), 0..) |field, i| { if (i == 0) { - writer.print(" {s} = ", .{field.name}) catch return 0; + Buffer.print(BufferAllocator, " {s} = ", .{field.name}) catch return 0; } else { - writer.print(", {s} = ", .{field.name}) catch return 0; + Buffer.print(BufferAllocator, ", {s} = ", .{field.name}) catch return 0; } switch (field.type) { f32, i32, u32, f64, i64, u64 => { - writer.print("{d}", .{@field(value, field.name)}) catch return 0; + Buffer.print(BufferAllocator, "{d}", .{@field(value, field.name)}) catch return 0; }, else => { - writer.print("", .{@typeName(field.type)}) catch return 0; + Buffer.print(BufferAllocator, "", .{@typeName(field.type)}) catch return 0; }, } } - writer.print(" }}" ++ "\x00", .{}) catch return 0; + Buffer.print(BufferAllocator, " }}" ++ "\x00", .{}) catch return 0; state.pop(1); state.pushString(Buffer.items) catch return 0; return 1; diff --git a/lib/objLoader/build.zig b/lib/objLoader/build.zig index 8a9bda4..381b62f 100644 --- a/lib/objLoader/build.zig +++ b/lib/objLoader/build.zig @@ -14,10 +14,12 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", ""); const tests = b.addTest(.{ - .target = target, - .optimize = optimize, - .root_source_file = b.path("src/obj_loader.zig"), - .link_libc = true, + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("src/obj_loader.zig"), + .link_libc = true, + }), }); tests.root_module.addImport("objLoader", mod);