mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +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
|
||||
|
||||
--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
|
||||
table.insert(t1, v)
|
||||
end
|
||||
if ... then
|
||||
return table.append_inplace(t1, ...)
|
||||
end
|
||||
return t1
|
||||
end
|
||||
|
||||
--return a new sequence with the elements of both t1 and t2
|
||||
function tablex.append(t1, t2)
|
||||
function tablex.append(t1, ...)
|
||||
local r = {}
|
||||
tablex.append_inplace(r, t1)
|
||||
tablex.append_inplace(r, t2)
|
||||
tablex.append_inplace(r, t1, ...)
|
||||
return r
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user