summaryrefslogtreecommitdiffstats
path: root/acf2/persistence/util.lua
blob: 249138136b6987eb069918800ac559d361d391a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--[[
Copyright (c) 2012-2013 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 = ''
   for line in file:lines() do data = data..line end
   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