Module:Sandbox/Hike395/Compact list explained
local getArgs = require('Module:Arguments').getArgslocal clist = require('Module:Collapsible list').mainlocal compressSparseArray = require('Module:TableTools').compressSparseArraylocal p =
--function p._main(args) local pattern = "^"..args[1].."_?(%d+)$" -- pattern to match local values = for k, v in pairs(args) do --- loop through all arguments if k
args[1] then --- if argument is just "foo", put it first values[1] = v else ord = tonumber(mw.ustring.match(k,pattern)) --- if "foo_?%d+", extract number if ord then values[ord+2] = v --- put value into list at number+2 (to keep "foo" first, even for foo0) end end end values = compressSparseArray(values) --- squeeze out gaps/nils in values, keep ordering local limit = tonumber(args._limit) or 4 if #values > limit then return clist(values) --- if longer than limit, call Module:Collapsible list end return mw.text.listToText(values) --- otherwise just print out pretty text listend
function p.main(frame) local args = getArgs(frame) return p._main(args)end
return p