Module:ConcatArgs: Difference between revisions

From LibMovIt Project
Jump to navigation Jump to search
d>TomT0m
(bugfix (tria))
 
m (1 revision imported: Import dei template listati da Camillo-Stefano ed esportati da Wikidata)
 
(No difference)

Latest revision as of 10:09, 31 January 2024

Documentation for this module may be created at Module:ConcatArgs/doc

local p = {}

function table.slice(tbl, first, last, step)
  local sliced = {}
  
  for i = first or 1, last or #tbl, step or 1 do
    sliced[#sliced+1] = tbl[i]
  end

  return sliced
end

p.slice = table.slice

local function count_args(table)
	local nargs = 0
	for num, _ in ipairs(table) do
		nargs = math.max(num, nargs)
	end
	return nargs
end



function p.ConcatArgs(frame)
	local pargs = frame:getParent().args
	local init = tonumber(frame.args["init"]) or frame.args["init"]
	
	local slice = table.slice(
		pargs,
		tostring(frame.args["min"]),
		count_args(pargs)
	)
	table.insert(slice, 1, pargs[init])
	return table.concat(slice, "|")
end

return p