diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-11-19 19:33:05 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-11-19 19:33:05 +0100 |
commit | 937040944ffdf7819b7ce7bee23a3d346718c0e4 (patch) | |
tree | db408e56ae414db637b1e58717d99bceda2cfcd5 /diller/cfg.lua | |
parent | 46f5784e3acb277aab44217e2521625ffe043d35 (diff) | |
download | esp-playground-master.tar.gz esp-playground-master.tar.bz2 esp-playground-master.tar.xz esp-playground-master.zip |
Diffstat (limited to 'diller/cfg.lua')
-rw-r--r-- | diller/cfg.lua | 36 |
1 files changed, 36 insertions, 0 deletions
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 |