summaryrefslogtreecommitdiffhomepage
path: root/src/ffluci/util.lua
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-03-25 23:34:21 +0000
committerSteven Barth <steven@midlink.org>2008-03-25 23:34:21 +0000
commit5f9910566de7165f4bb0ee62bc3ace53c708a94e (patch)
treeda06cbacc22d9d74b1e160e6dcf19fe0f62fa432 /src/ffluci/util.lua
parent9fa7e0e92ddae9ff68f50ad20bbdfc8a3c09135a (diff)
* Entering Version 0.2
* Completed CBI * Minor bugfixes and enhancements
Diffstat (limited to 'src/ffluci/util.lua')
-rw-r--r--src/ffluci/util.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/ffluci/util.lua b/src/ffluci/util.lua
index caa8e41de..082310fbf 100644
--- a/src/ffluci/util.lua
+++ b/src/ffluci/util.lua
@@ -56,6 +56,23 @@ function class(base)
end
+-- Clones an object (deep on-demand)
+function clone(object, deep)
+ local copy = {}
+
+ for k, v in pairs(object) do
+ if deep and type(v) == "table" then
+ v = clone(v, deep)
+ end
+ copy[k] = v
+ end
+
+ setmetatable(copy, getmetatable(object))
+
+ return copy
+end
+
+
-- Checks whether a table has an object "value" in it
function contains(table, value)
for k,v in pairs(table) do
@@ -146,6 +163,28 @@ function sessionid()
return ENV.SESSIONID
end
+
+-- Splits a string into an array (Taken from lua-users.org)
+function split(str, pat)
+ local t = {}
+ local fpat = "(.-)" .. pat
+ local last_end = 1
+ local s, e, cap = str:find(fpat, 1)
+ while s do
+ if s ~= 1 or cap ~= "" then
+ table.insert(t,cap)
+ end
+ last_end = e+1
+ s, e, cap = str:find(fpat, last_end)
+ end
+ if last_end <= #str then
+ cap = str:sub(last_end)
+ table.insert(t, cap)
+ end
+ return t
+end
+
+
-- Updates the scope of f with "extscope"
function updfenv(f, extscope)
local scope = getfenv(f)