Module:Sandbox/Pi zero
Appearance
[create] Documentation
local export = {}
local function tabulate( args )
local s = ''
for k, v in pairs( args ) do
s = s .. '|-\n| ' .. k .. '\n| <code>' .. v .. '</code>\n'
end
if s ~= '' then
s = '{| class="wikitable"\n|-\n! key\n! value\n' .. s .. '|}'
end
return s
end
export.echo = function( frame )
local mp = tabulate( frame.args )
local cp = tabulate( frame:getParent().args )
if mp ~= '' then
mp = 'module parameters:\n' .. mp .. '\n'
end
if cp ~= '' then
cp = 'context parameters:\n' .. cp .. '\n'
else
cp = 'no context parameters.\n'
end
return mp .. cp
end
export.dispatch = function( frame )
local title = frame.args[1]
local args = {}
for v, k in pairs( frame:getParent().args ) do
args[v] = k
end
for v, k in pairs( frame.args ) do
if type( v ) == "number" then
if v ~= 1 then
args[ tonumber( v ) - 1 ] = k
end
else
args[v] = k
end
end
return frame:expandTemplate{ title = title, args = args }
end
export.push = function( frame )
local title = frame.args[1]
local args = {}
local displace = 0;
for v, k in pairs( frame.args ) do
if type( v ) == "number" then
if v ~= 1 then
local nv = tonumber( v ) - 1
args[ nv ] = k
displace = math.max( displace, nv )
end
end
end
for v, k in pairs( frame:getParent().args ) do
if type( v ) == "number" then
args[ tonumber( v ) + displace ] = k
else
args[v] = k
end
end
for v, k in pairs( frame.args ) do
if type( v ) ~= "number" then
args[v] = k
end
end
return frame:expandTemplate{ title = title, args = args }
end
export.dispatchNamed = function( frame )
local title = frame.args[1]
local args = {}
for v, k in pairs( frame:getParent().args ) do
if type( v ) ~= "number" then
args[v] = k
end
end
for v, k in pairs( frame.args ) do
if type( v ) == "number" then
if v ~= 1 then
args[ tonumber( v ) - 1 ] = k
end
else
args[v] = k
end
end
return frame:expandTemplate{ title = title, args = args }
end
export.static = function( frame )
return frame:getParent():getTitle()
end
return export