chroma_solstice/tools/compile_ink.lua

32 lines
1.1 KiB
Lua
Raw Permalink Normal View History

2026-08-08 00:09:44 -04:00
-- Compile Ink source (stories/*.ink) into the pre-parsed .lua books the game
-- loads. LÖVE ships no lpeg, so parsing happens here, once, at author time;
-- the game only ever requires the compiled .lua. Needs a standalone `lua` with
-- lpeg installed (Arch: pacman -S lua-lpeg).
--
-- Run from the project root:
-- lua tools/compile_ink.lua # compile every stories/*.ink
-- lua tools/compile_ink.lua start_sign # compile stories/start_sign.ink
-- lua tools/compile_ink.lua stories/foo.ink # explicit path
package.path = package.path .. ";libs/narrator/?.lua"
local narrator = require("narrator.narrator")
local function compile(path)
narrator.parse_file(path, { save = true })
print("compiled " .. path .. " -> " .. (path:gsub("%.ink$", "") .. ".lua"))
end
local targets = {}
if #arg == 0 then
local ls = io.popen("ls stories/*.ink 2>/dev/null")
for line in ls:lines() do table.insert(targets, line) end
ls:close()
else
for _, a in ipairs(arg) do
table.insert(targets, a:match("%.ink$") and a or ("stories/" .. a .. ".ink"))
end
end
assert(#targets > 0, "no .ink files to compile")
for _, t in ipairs(targets) do compile(t) end