From 3b507677e10f965184d7ec50f2ba86be24556e1f Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Tue, 7 Mar 2023 16:34:13 +0100 Subject: [PATCH] mzte-nv will pass info about source file to fennel --- mzte-nv/src/compiler.zig | 9 ++++++++- mzte-nv/src/ser.zig | 16 +++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/mzte-nv/src/compiler.zig b/mzte-nv/src/compiler.zig index 2e82df8..75b6096 100644 --- a/mzte-nv/src/compiler.zig +++ b/mzte-nv/src/compiler.zig @@ -1,6 +1,7 @@ const std = @import("std"); const ffi = @import("ffi.zig"); const c = ffi.c; +const ser = @import("ser.zig"); const log = std.log.scoped(.compiler); @@ -135,7 +136,13 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void { // fennel.compile-string c.lua_getfield(l, -3, "compile-string"); ffi.luaPushString(l, data); - if (c.lua_pcall(l, 1, 1, 0) != 0) { + // push fennel compile options + ser.luaPushAny(l.?, .{ + .filename = luafile, + // no need for indenting, this code will likely not be seen by anyone + .indent = "", + }); + if (c.lua_pcall(l, 2, 1, 0) != 0) { log.warn( "error compiling fennel object {s}: {s}", .{ luafile, ffi.luaToString(l, -1) }, diff --git a/mzte-nv/src/ser.zig b/mzte-nv/src/ser.zig index 2ce6a54..0e8c1e8 100644 --- a/mzte-nv/src/ser.zig +++ b/mzte-nv/src/ser.zig @@ -1,5 +1,6 @@ const std = @import("std"); -const c = @import("ffi.zig").c; +const ffi = @import("ffi.zig"); +const c = ffi.c; pub fn luaPushAny(l: *c.lua_State, x: anytype) void { const T = @TypeOf(x); @@ -14,16 +15,17 @@ pub fn luaPushAny(l: *c.lua_State, x: anytype) void { .One => { if (T == c.lua_CFunction or T == @typeInfo(c.lua_CFunction).Optional.child) - c.lua_pushcfunction(l, x) - else + { + c.lua_pushcfunction(l, x); + } else if (@typeInfo(P.child) == .Array) { + luaPushAny(l, @as([]const std.meta.Elem(P.child), x)); + } else { luaPushAny(l, x.*); + } }, .Slice => { if (P.child == u8) { - if (P.sentinel == null) - @compileError("luaPushAny doesn't support " ++ @typeName(T)); - - c.lua_pushstring(l, x.ptr); + ffi.luaPushString(l, x); } else { c.lua_createtable(l, x.len, 0);