mzte-nv will pass info about source file to fennel

This commit is contained in:
LordMZTE 2023-03-07 16:34:13 +01:00
parent 7cb4f971d0
commit 3b507677e1
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
2 changed files with 17 additions and 8 deletions

View file

@ -1,6 +1,7 @@
const std = @import("std"); const std = @import("std");
const ffi = @import("ffi.zig"); const ffi = @import("ffi.zig");
const c = ffi.c; const c = ffi.c;
const ser = @import("ser.zig");
const log = std.log.scoped(.compiler); const log = std.log.scoped(.compiler);
@ -135,7 +136,13 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
// fennel.compile-string // fennel.compile-string
c.lua_getfield(l, -3, "compile-string"); c.lua_getfield(l, -3, "compile-string");
ffi.luaPushString(l, data); 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( log.warn(
"error compiling fennel object {s}: {s}", "error compiling fennel object {s}: {s}",
.{ luafile, ffi.luaToString(l, -1) }, .{ luafile, ffi.luaToString(l, -1) },

View file

@ -1,5 +1,6 @@
const std = @import("std"); 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 { pub fn luaPushAny(l: *c.lua_State, x: anytype) void {
const T = @TypeOf(x); const T = @TypeOf(x);
@ -14,16 +15,17 @@ pub fn luaPushAny(l: *c.lua_State, x: anytype) void {
.One => { .One => {
if (T == c.lua_CFunction or if (T == c.lua_CFunction or
T == @typeInfo(c.lua_CFunction).Optional.child) 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.*); luaPushAny(l, x.*);
}
}, },
.Slice => { .Slice => {
if (P.child == u8) { if (P.child == u8) {
if (P.sentinel == null) ffi.luaPushString(l, x);
@compileError("luaPushAny doesn't support " ++ @typeName(T));
c.lua_pushstring(l, x.ptr);
} else { } else {
c.lua_createtable(l, x.len, 0); c.lua_createtable(l, x.len, 0);