summaryrefslogtreecommitdiffstats
path: root/aconf/persistence/util.lua
diff options
context:
space:
mode:
Diffstat (limited to 'aconf/persistence/util.lua')
-rw-r--r--aconf/persistence/util.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/aconf/persistence/util.lua b/aconf/persistence/util.lua
new file mode 100644
index 0000000..d233b1d
--- /dev/null
+++ b/aconf/persistence/util.lua
@@ -0,0 +1,27 @@
+--[[
+Copyright (c) 2012-2014 Kaarle Ritvanen
+See LICENSE file for license details
+--]]
+
+local M = {}
+
+function M.open_file(path, mode)
+ local file = io.open(path, mode)
+ if not file then error('Cannot open file: '..path) end
+ return file
+end
+
+function M.read_file(path)
+ local file = M.open_file(path)
+ local data = file:read('*all')
+ file:close()
+ return data
+end
+
+function M.tostring(value)
+ -- TODO make values configurable per address
+ if type(value) == 'boolean' then return value and 'yes' or 'no' end
+ return tostring(value)
+end
+
+return M