[added] tablex.append_inplace and tablex.append can both take variable numbers of tables

This commit is contained in:
Max Cahill 2021-03-05 12:07:28 +11:00
parent 290b39236c
commit 24bcc78616

View File

@ -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