From 937040944ffdf7819b7ce7bee23a3d346718c0e4 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 19 Nov 2015 19:33:05 +0100 Subject: Major refactoring, splitting stuff into separate files. --- diller/cfg.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 diller/cfg.lua (limited to 'diller/cfg.lua') diff --git a/diller/cfg.lua b/diller/cfg.lua new file mode 100644 index 0000000..2a8472c --- /dev/null +++ b/diller/cfg.lua @@ -0,0 +1,36 @@ +function info(msg) + print("info msg="..msg) +end + +function read_cfg(name, required) + local filename = "cfg-"..name + if not file.open(filename, "r") then + if required then + panic("Could not read configuration file: "..filename) + else + return nil + end + end + local value = file.readline() + file.close() + if value == nil or #value == 0 then + if required then + panic("Empty configuration file: "..filename) + else + return nil + end + end + return string.sub(value, 1, -2) +end + +function write_cfg(name, value) + local filename = "cfg-"..name + local ok + ok = file.open(filename, "w+") + if ok then + ok = file.writeline(value) + file.flush() + file.close() + end + return ok +end -- cgit v1.2.3