Module:table/append

Revision as of 12:34, 9 May 2026 by Sware (talk | contribs) (Created page with "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")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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