mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 22:24:35 +00:00
[added] tablex.append_inplace
and tablex.append
can both take variable numbers of tables
This commit is contained in:
parent
290b39236c
commit
24bcc78616
10
tablex.lua
10
tablex.lua
@ -182,18 +182,20 @@ function tablex.values(t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--append sequence t2 into t1, modifying t1
|
--append sequence t2 into t1, modifying t1
|
||||||
function tablex.append_inplace(t1, t2)
|
function tablex.append_inplace(t1, t2, ...)
|
||||||
for i,v in ipairs(t2) do
|
for i,v in ipairs(t2) do
|
||||||
table.insert(t1, v)
|
table.insert(t1, v)
|
||||||
end
|
end
|
||||||
|
if ... then
|
||||||
|
return table.append_inplace(t1, ...)
|
||||||
|
end
|
||||||
return t1
|
return t1
|
||||||
end
|
end
|
||||||
|
|
||||||
--return a new sequence with the elements of both t1 and t2
|
--return a new sequence with the elements of both t1 and t2
|
||||||
function tablex.append(t1, t2)
|
function tablex.append(t1, ...)
|
||||||
local r = {}
|
local r = {}
|
||||||
tablex.append_inplace(r, t1)
|
tablex.append_inplace(r, t1, ...)
|
||||||
tablex.append_inplace(r, t2)
|
|
||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user