Add luci.util.append
This commit is contained in:
parent
8d9a130b70
commit
676966f78b
1 changed files with 18 additions and 11 deletions
|
@ -320,23 +320,30 @@ function parse_units(ustr)
|
||||||
return val
|
return val
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- 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
|
||||||
|
src[#src+1] = v
|
||||||
|
end
|
||||||
|
else
|
||||||
|
src[#src+1] = a
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return src
|
||||||
|
end
|
||||||
|
|
||||||
--- Combines two or more numerically indexed tables and single objects into one table.
|
--- Combines two or more numerically indexed tables and single objects into one table.
|
||||||
-- @param tbl1 Table value to combine
|
-- @param tbl1 Table value to combine
|
||||||
-- @param tbl2 Table value to combine
|
-- @param tbl2 Table value to combine
|
||||||
-- @param ... More tables to combine
|
-- @param ... More tables to combine
|
||||||
-- @return Table value containing all values of given tables
|
-- @return Table value containing all values of given tables
|
||||||
function combine(...)
|
function combine(...)
|
||||||
local result = {}
|
return append({}, ...)
|
||||||
for i, a in ipairs({...}) do
|
|
||||||
if type(a) == "table" then
|
|
||||||
for j, v in ipairs(a) do
|
|
||||||
result[#result+1] = v
|
|
||||||
end
|
|
||||||
else
|
|
||||||
result[#result+1] = a
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Checks whether the given table contains the given value.
|
--- Checks whether the given table contains the given value.
|
||||||
|
|
Loading…
Reference in a new issue