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
add info on trimming and removing blanks
(add wrapper function info)
(add info on trimming and removing blanks)
Line 72:
 
return p
</source>
 
=== Options ===
 
The following options are available. They are explained in the sections below.
 
<source lang="lua">
local args = getArgs(frame, {
trim = false,
removeBlanks = false,
valueFunc = function(key, val)
-- Code for processing one argument
end,
parentFirst = true,
readOnly = true,
noOverwrite = true
})
</source>
 
=== Trimming and removing blanks ===
 
Blank arguments often trip up coders new to converting MediaWiki templates to Lua. In template syntax, blank strings and strings consisting only of whitespace are considered false. However, in Lua, blank strings and strings consisting of whitespace are considered true. This means that if you don't pay attention to such arguments when you write your Lua modules, you might treat something as true that should actually be treated as false. To avoid this, by default this module removes all blank arguments.
 
Similarly, whitespace can cause problems when dealing with positional arguments. Although whitespace is trimmed for named arguments coming from #invoke, it is preserved for positional arguments. Most of the time this additional whitespace is not desired, so this module trims it off by default.
 
However, sometimes you want to use blank arguments as input, and sometimes you want to keep additional whitespace. This can be necessary to convert some templates exactly as they were written. If you want to do this, you can set the <code>trim</code> and <code>removeBlanks</code> arguments to <code>false</code>.
 
<source lang="lua">
local args = getArgs(frame, {
trim = false,
removeBlanks = false,
})
</source>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu