summaryrefslogtreecommitdiffhomepage
path: root/src/ffluci/util.lua
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-03-12 20:52:28 +0000
committerSteven Barth <steven@midlink.org>2008-03-12 20:52:28 +0000
commitffe39ec1babf58fef087bd580d7ad0725d9b3389 (patch)
tree35c2822aa9dd1e2640324856cb0b467df582c9cf /src/ffluci/util.lua
parent93a98dd13be5127871ff78d85e8199f2df77e9c2 (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/util.lua')
-rw-r--r--src/ffluci/util.lua54
1 files changed, 38 insertions, 16 deletions
diff --git a/src/ffluci/util.lua b/src/ffluci/util.lua
index 07cbb8000c..3004f552e6 100644
--- a/src/ffluci/util.lua
+++ b/src/ffluci/util.lua
@@ -26,6 +26,26 @@ limitations under the License.
module("ffluci.util", package.seeall)
+
+-- Lua OO class support emulation
+function class(base)
+ local clsobj = {}
+ local metatable = {__index = clsobj}
+
+ function clsobj.new()
+ local inst = {}
+ setmetatable(inst, metatable)
+ return inst
+ end
+
+ if base then
+ setmetatable(clsobj, {__index = base})
+ end
+
+ return clsobj
+end
+
+
-- Checks whether a table has an object "value" in it
function contains(table, value)
for k,v in pairs(table) do
@@ -57,24 +77,26 @@ end
-- Runs "command" and returns its output
-function exec(command, return_array)
+function exec(command)
local pp = io.popen(command)
- local data = nil
+ local data = pp:read("*a")
+ pp:close()
- if return_array then
- local line = ""
- data = {}
-
- while true do
- line = pp:read()
- if (line == nil) then break end
- table.insert(data, line)
- end
- pp:close()
- else
- data = pp:read("*a")
- pp:close()
- end
+ return data
+end
+
+-- Runs "command" and returns its output as a array of lines
+function execl(command)
+ local pp = io.popen(command)
+ local line = ""
+ local data = {}
+
+ while true do
+ line = pp:read()
+ if (line == nil) then break end
+ table.insert(data, line)
+ end
+ pp:close()
return data
end