diff options
author | Steven Barth <steven@midlink.org> | 2008-03-25 23:34:21 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-03-25 23:34:21 +0000 |
commit | 5f9910566de7165f4bb0ee62bc3ace53c708a94e (patch) | |
tree | da06cbacc22d9d74b1e160e6dcf19fe0f62fa432 /src/ffluci/util.lua | |
parent | 9fa7e0e92ddae9ff68f50ad20bbdfc8a3c09135a (diff) |
* Entering Version 0.2
* Completed CBI
* Minor bugfixes and enhancements
Diffstat (limited to 'src/ffluci/util.lua')
-rw-r--r-- | src/ffluci/util.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/ffluci/util.lua b/src/ffluci/util.lua index caa8e41de3..082310fbfa 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) |