Jump to content

Module:table/append

From Wiktionary, the free dictionary

local select = select  local function append(n, i, t, t_len, item, ...) local k = 0 while true do k = k + 1 local v = item[k] if v ~= nil then t_len = t_len + 1 t[t_len] = v elseif i == n then return t else return append(n, i + 1, t, t_len, ...) end end end  --[==[ Appends any number of lists together as a new list.]==] return function(...) local n, t = select("#", ...), {} return n == 0 and t or append(n, 1, t, 0, ...) end