From 5f9910566de7165f4bb0ee62bc3ace53c708a94e Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Tue, 25 Mar 2008 23:34:21 +0000 Subject: * Entering Version 0.2 * Completed CBI * Minor bugfixes and enhancements --- src/ffluci/util.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/ffluci/util.lua') 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) -- cgit v1.2.3