Module:Utilisateur:Maëlan/TestLua
Apparence
La documentation pour ce module peut être créée à Module:Utilisateur:Maëlan/TestLua/Documentation
local M = {}
--- function appelable depuis un modèle WikiCode ?
function M.test_gen(frame, x, y)
local parent = frame:getParent().args
local txt = ''
txt = txt .. '{parent.1=' .. (parent[1] or '---') .. '}'
txt = txt .. '{parent.2=' .. (parent[2] or '---') .. '}'
txt = txt .. '{parent.p=' .. (parent["p"] or '---') .. '}'
txt = txt .. '{1=' .. (frame.args[1] or '---') .. '}'
txt = txt .. '{2=' .. (frame.args[2] or '---') .. '}'
txt = txt .. '{p=' .. (frame.args["p"] or '---') .. '}'
txt = txt .. '{x=' .. (x or '---') .. '}'
txt = txt .. '{y=' .. (y or '---') .. '}'
return txt
end
--- fonction appelable depuis un modèle WikiCode
function M.test(frame)
return p.test_gen(frame, 'aaa', 'bbb')
end
--- liste tous les arguments de la frame donnée
function list_frame_params(frame, title, indent)
indent = indent or ''
local txt = indent
if title == nil then
txt = txt .. 'arguments :\n'
else
txt = txt .. title .. ' :\n'
end
for param_name, param_value in pairs(frame.args) do
local esc_name
if type(param_name) == 'number' then
esc_name = param_name
elseif type(param_name) == 'string' then
esc_name = mw.ustring.format('"%s"', param_name)
else
assert(false)
end
txt = mw.ustring.format("%s%s* '''<code>%s</code>''' = <code>\"%s\"</code>\n", txt, indent, esc_name, param_value)
end
return txt
end
--- fonction destinée à être appelée via {{#invoke}}, éventuellement dans un
--- modèle
function M.list_params(frame)
return
list_frame_params(frame:getParent(), 'arguments fournis au modèle qui invoque Lua', ':') .. '\n' ..
list_frame_params(frame, 'arguments fournis à {{#invoke}}', ':')
end
return M