DKL9 GitList
Repositories
DKL9 home
memoire
Code
Commits
Branches
Tags
Search
Tree:
b39812d
Branches
Tags
master
memoire
src
loader.lua
Reformulate data structures
John Smith
commited
b39812d
at 2023-177 12:35:37
loader.lua
Blame
History
Raw
--[[ deck loading and saving functions (working with Recfiles) ]] local Card = dofile(SRC_DIR .. "card.lua") local recrw = dofile(SRC_DIR .. "recrw.lua") --[[ load a deck (a table of `Card`s) from a Recfile ]] local function loaddeck(fname, conf) local fh = io.open(fname) if not fh then print("no fh") return nil end local rt = fh:read "a" if not rt then print("no read") return nil end fh:close() local pr = recrw.read(rt) if not pr then print("no recs") return nil end local ep = Card:fromrecs(pr, conf) if not ep then print("no cards") return nil end return ep end --[[ save a deck (a table of `Card`s) to a Recfile ]] local function savedeck(fname, deck) local rrf = {} for i, cg in ipairs(deck) do rrf[i] = cg:torec() 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 }