31 lines
1.1 KiB
Lua
31 lines
1.1 KiB
Lua
-- 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
|