diff options
author | Steven Barth <steven@midlink.org> | 2008-03-12 20:52:28 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-03-12 20:52:28 +0000 |
commit | ffe39ec1babf58fef087bd580d7ad0725d9b3389 (patch) | |
tree | 35c2822aa9dd1e2640324856cb0b467df582c9cf /src/ffluci/fs.lua | |
parent | 93a98dd13be5127871ff78d85e8199f2df77e9c2 (diff) |
Added module for system abstraction
Rewrote readfile and exec functions
Moved some orpahned example file out of the way
Diffstat (limited to 'src/ffluci/fs.lua')
-rw-r--r-- | src/ffluci/fs.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/ffluci/fs.lua b/src/ffluci/fs.lua index 5a1cc6b351..55da9b8dce 100644 --- a/src/ffluci/fs.lua +++ b/src/ffluci/fs.lua @@ -31,14 +31,36 @@ require("lfs") -- Returns the content of file function readfile(filename) local fp = io.open(filename) + if fp == nil then error("Unable to open file for reading: " .. filename) end + local data = fp:read("*a") fp:close() return data end +-- Returns the content of file as array of lines +function readfilel(filename) + local fp = io.open(filename) + local line = "" + local data = {} + + if fp == nil then + error("Unable to open file for reading: " .. filename) + end + + while true do + line = fp:read() + if (line == nil) then break end + table.insert(data, line) + end + + fp:close() + return data +end + -- Writes given data to a file function writefile(filename, data) local fp = io.open(filename, "w") |