Module:Arguments/doc: Difference between revisions
From Mariopedia, a wiki on Mario, Yoshi, Wario, Donkey Kong, Super Smash Bros., and more!
Jump to navigationJump to search
Content deleted Content added
put frame examples in tables for easier comparison |
→Custom formatting of arguments: tweak valueFunc examples so that they don't break with nil arguments, and make all code paths return explicit nils |
||
Line 120:
if key == 1 then
return value
elseif value then
else▼
value = mw.text.trim(value)
if value ~= '' then
Line 126:
end
end
return nil
end
})
Line 134 ⟶ 135:
local args = getArgs(frame, {
valueFunc = function (key, value)
if not value then
return nil
end
value = mw.ustring.lower(value)
if mw.ustring.find(value, '%S') then
return value
end
return nil
end
})
</source>
Note: the above functions will fail if passed input that is not of type <code>string</code> or <code>nil</code>. This might be the case if you use the <code>getArgs</code> function in the main function of your module, and that function is called by another Lua module. In this case, you will need to check the type of your input. This is not a problem if you are using a function specially for arguments from #invoke (i.e. you have <code>p.main</code> and <code>p._main</code> functions, or something similar).
{{cot|Examples 1 and 2 with type checking}}
Line 155 ⟶ 160:
if value ~= '' then
return value
▲ else
return nil
end
else
Line 171 ⟶ 178:
if mw.ustring.find(value, '%S') then
return value
else
return nil
end
else
|