1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00
anselme/run.lua
2019-12-25 15:53:32 +01:00

37 lines
765 B
Lua

require("candran").setup()
local vm = require("anselme")()
vm:loaddirectory(".")
vm:loadfile("test.ans")
print(require("inspect")(vm.state))
while true do
local e, d = vm:step()
if e == "text" then
for _, t in ipairs(d) do
print(t.text)
for k,v in pairs(t.tags) do
print("> "..tostring(k)..": "..tostring(v))
end
end
print("-----")
elseif e == "choice" then
for i, c in ipairs(d) do
print(tostring(i)..": "..c.text)
for k,v in pairs(c.tags) do
print("> "..tostring(k)..": "..tostring(v))
end
end
local choice
repeat
choice = tonumber(io.read("*l"))
until choice ~= nil and choice > 0 and choice <= #d
vm:choose(choice)
elseif e == "end" then
break
else
error("unknown event ("..tostring(e)..")")
end
end