summaryrefslogtreecommitdiffhomepage
path: root/libs/core
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-10-30 19:10:39 +0000
committerSteven Barth <steven@midlink.org>2008-10-30 19:10:39 +0000
commit676966f78bbe4aa42f819b991586dca0bac8c554 (patch)
treeab16c0d68dc0bc16edfe1ce2654e2f38de6dd92c /libs/core
parent8d9a130b70b532bff0ffd01b81481a040c25a53b (diff)
Add luci.util.append
Diffstat (limited to 'libs/core')
-rw-r--r--libs/core/luasrc/util.lua27
1 files changed, 17 insertions, 10 deletions
diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua
index 6498a4976..109ccab28 100644
--- a/libs/core/luasrc/util.lua
+++ b/libs/core/luasrc/util.lua
@@ -320,23 +320,30 @@ function parse_units(ustr)
return val
end
---- Combines two or more numerically indexed tables and single objects into one table.
--- @param tbl1 Table value to combine
--- @param tbl2 Table value to combine
--- @param ... More tables to combine
--- @return Table value containing all values of given tables
-function combine(...)
- local result = {}
+--- Appends numerically indexed tables or single objects to a given table.
+-- @param src Target table
+-- @param ... Objects to insert
+-- @return Target table
+function append(src, ...)
for i, a in ipairs({...}) do
if type(a) == "table" then
for j, v in ipairs(a) do
- result[#result+1] = v
+ src[#src+1] = v
end
else
- result[#result+1] = a
+ src[#src+1] = a
end
end
- return result
+ return src
+end
+
+--- Combines two or more numerically indexed tables and single objects into one table.
+-- @param tbl1 Table value to combine
+-- @param tbl2 Table value to combine
+-- @param ... More tables to combine
+-- @return Table value containing all values of given tables
+function combine(...)
+ return append({}, ...)
end
--- Checks whether the given table contains the given value.