summaryrefslogtreecommitdiffhomepage
path: root/src/ffluci/util.lua
diff options
context:
space:
mode:
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 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)