DKL9 GitList
Repositories
DKL9 home
memoire
Code
Commits
Branches
Tags
Search
Tree:
6975b4b
Branches
Tags
master
memoire
loader.lua
Fix bug in 9b023b3
John Smith
commited
6975b4b
at 2022-206 08:50:59
loader.lua
Blame
History
Raw
--[[ deck loading and saving functions (working with Recfiles) ]] local SRC_DIR = arg[0]:match("^.*/") or "" local Prompt = dofile(SRC_DIR .. "prompt.lua") local recrw = dofile(SRC_DIR .. "recrw.lua") --[[ load a deck (a table of tables of `Prompt`s) from a Recfile ]] local function loaddeck(fname, conf) local fh = io.open(fname) if not fh then return nil end local rt = fh:read "a" if not rt then return nil end fh:close() local pr = recrw.read(rt) if not pr then return nil end local ep = Prompt:fromrecs(pr, conf) return ep end --[[ save a deck (a table of tables of `Prompt`s) to a Recfile ]] local function savedeck(fname, deck) local rrf = {} for i, cg in ipairs(deck) do rrf[i] = Prompt:torec(cg) end local wot = recrw.write(rrf) local fh = io.open(fname, "w") if not fh then io.write("couldn't open output\n") end local wr, err = fh:write(wot) if not wr then io.write("couldn't write to output\n") end fh:close() end return { load = loaddeck, save = savedeck }