objloader, nfd, and lua updated
This commit is contained in:
parent
5d5e99b9c5
commit
774feb364d
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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("<unknown type {s}>", .{@typeName(field.type)}) catch return 0;
|
||||
Buffer.print(BufferAllocator, "<unknown type {s}>", .{@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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue