From edad4fc123099a780d960feea4fe37efb6d979d8 Mon Sep 17 00:00:00 2001 From: T Date: Tue, 26 May 2026 10:33:24 -0600 Subject: include and link lua 5.4, smoke test in panto cli main.zig --- src/main.zig | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src') diff --git a/src/main.zig b/src/main.zig index 20da910..6fbdb4b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,6 +2,14 @@ const std = @import("std"); const panto = @import("panto"); const ping_tool = @import("ping_tool.zig"); +// Lua 5.4 C API. Linked statically via build.zig from the upstream lua.org +// source tarball pinned in build.zig.zon. +const lua = @cImport({ + @cInclude("lua.h"); + @cInclude("lauxlib.h"); + @cInclude("lualib.h"); +}); + const Receiver = panto.provider.Receiver; const ReceiverVTable = panto.provider.ReceiverVTable; const ContentBlockType = panto.provider.ContentBlockType; @@ -92,6 +100,26 @@ const CLIReceiver = struct { } }; +/// Spin up a Lua interpreter, run a no-op, tear it down. Catches +/// link/compile errors on the Lua dependency at the earliest moment. +/// Logs only in debug builds; release builds run silently. +fn luaSmokeCheck() void { + const L = lua.luaL_newstate() orelse { + std.log.err("lua: luaL_newstate returned null", .{}); + return; + }; + defer lua.lua_close(L); + lua.luaL_openlibs(L); + + // Push _VERSION to confirm libs loaded. + _ = lua.lua_getglobal(L, "_VERSION"); + const ver = lua.lua_tolstring(L, -1, null); + if (ver != null) { + std.log.debug("lua: {s} linked OK", .{ver}); + } + lua.lua_settop(L, 0); +} + fn loadConfig(environ_map: *const std.process.Environ.Map) !panto.config.Config { const style_str = environ_map.get("PANTO_API_STYLE") orelse "openai_chat"; const style = std.meta.stringToEnum(panto.config.APIStyle, style_str) orelse { @@ -167,6 +195,10 @@ pub fn main(init: std.process.Init) !void { const alloc = init.gpa; const io = init.io; + // Smoke test: prove Lua is linked. Slice 1 — no extension runtime + // wired up yet, this just confirms the static lib comes through. + luaSmokeCheck(); + const config = try loadConfig(init.environ_map); var stdout_buffer: [4096]u8 = undefined; -- cgit v1.3