aboutsummaryrefslogtreecommitdiff
path: root/diller/cfg.lua
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-11-19 19:33:05 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-11-19 19:33:05 +0100
commit937040944ffdf7819b7ce7bee23a3d346718c0e4 (patch)
treedb408e56ae414db637b1e58717d99bceda2cfcd5 /diller/cfg.lua
parent46f5784e3acb277aab44217e2521625ffe043d35 (diff)
downloadesp-playground-master.tar.gz
esp-playground-master.tar.bz2
esp-playground-master.tar.xz
esp-playground-master.zip
Major refactoring, splitting stuff into separate files.HEADmaster
Diffstat (limited to 'diller/cfg.lua')
-rw-r--r--diller/cfg.lua36
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