Actions

Module

ArgumentPairs demo

From Whonix

This module shows the sorted name-value combinations from parameter definitions like in a template call.

Example (the f is not part of the parameter definitions):

{{#invoke:ArgumentPairs demo|f|hi=c|g|e=y|d|h=i}} gives:

Lua error: Internal error: The interpreter exited with status 1.

Assignments are done from left to right, in the case of multiple assignments to the same parameter (named or unnamed) the last one counts:

{{#invoke:ArgumentPairs demo|f|1=q|hi=c|g|e=y|d|h=i|e=k|2=p}} gives:

Lua error: Internal error: The interpreter exited with status 1.

Types[edit]

Types of the results of "for n,v in frame:argumentPairs() do" inside the lua program:

  • n is of type number if it is implicitly given, or if the supplied wikitext for it represents an integer value, otherwise string
  • v is of type string

Script error: Lua error: Internal error: The interpreter exited with status 1.

local p = {}
 
function comp(x,y)
    return tostring(x[1])<tostring(y[1])
end
 
function p.f(frame)
    local t={}
    for n,v in frame:argumentPairs() do table.insert (t,{n,v}) end
    table.sort (t,comp)
    r = '{|class="wikitable sortable"\n!name!!value\n'
    for i,nv in ipairs(t) do r = r..'|-\n|'..nv[1]..'||'..nv[2]..'\n' end
    r=r..'|}'
    return r
end
 
return p