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 about the frameOnly and parentOnly options
(add info on ref tags and known limitations, add type checking examples for the valueFunc option)
(add info about the frameOnly and parentOnly options)
Line 86:
-- Code for processing one argument
end,
frameOnly = true,
parentOnly = true,
parentFirst = true,
readOnly = true,
Line 179 ⟶ 181:
=== Frames and parent frames ===
 
Arguments in the <code>args</code> table can be passed from the current frame or from its parent frame at the same time. To understand what this means, it is easiest to give an example. Let's say that we have a module called <code>Module:ExampleArgs</code>. This module prints the first threetwo positional arguments that it is passed.
 
{{cot|Module:ExampleArgs code}}
Line 194 ⟶ 196:
local first = args[1] or ''
local second = args[2] or ''
return first .. ' ' .. second .. ' ' .. third
local third = args[3] or ''
return first .. ' ' .. second .. ' ' .. third
end
 
Line 202 ⟶ 203:
{{cob}}
 
<code>Module:ExampleArgs</code> is then called by <code>Template:ExampleArgs</code>, which contains the code <code><nowiki>{{#invoke:ExampleArgs|main|firstArgfirstInvokeArg}}</nowiki></code>. This produces the result "firstArgfirstInvokeArg".
 
Now if we were to call <code>Template:ExampleArgs</code>, the following would happen:
 
#* <code><nowiki>{{ExampleArgs}}</nowiki></code> &rarr; firstArg firstInvokeArg
#* <code><nowiki>{{ExampleArgs|myFirstArgfirstTemplateArg}}</nowiki></code> &rarr; firstArg firstInvokeArg
#* <code><nowiki>{{ExampleArgs|myFirstArgfirstTemplateArg|mySecondArg|myThirdArgsecondTemplateArg}}</nowiki></code> &rarr; firstArg mySecondArgfirstInvokeArg myThirdArgsecondTemplateArg
 
There are three options you can set to change this behaviour: <code>frameOnly</code>, <code>parentOnly</code> and <code>parentFirst</code>. If you set <code>frameOnly</code> then only arguments passed from the current frame will be accepted; if you set <code>parentOnly</code> then only only arguments passed from the parent frame will be accepted; and if you set <code>parentFirst</code> then arguments will be passed from both the current and parent frames, but the parent frame will have priority over the current frame. Here are the results in terms of <code>Template:ExampleArgs</code>:
If you want the value from the parent frame to have precedence over the value from the current frame (i.e. if you would like "myFirstArg" instead of "firstArg" in the second example above), you can do so with the <code>parentFirst</code> option.
 
* <code>frameOnly</code>
<source lang="lua">
** <code><nowiki>{{ExampleArgs}}</nowiki></code> &rarr; firstInvokeArg
local args = getArgs(frame, {
** <code><nowiki>{{ExampleArgs|firstTemplateArg}}</nowiki></code> &rarr; firstInvokeArg
parentFirst = true
** <code><nowiki>{{ExampleArgs|firstTemplateArg|secondTemplateArg}}</nowiki></code> &rarr; firstInvokeArg
})
* <code>parentOnly</code>
</source>
** <code><nowiki>{{ExampleArgs}}</nowiki></code> &rarr;
** <code><nowiki>{{ExampleArgs|firstTemplateArg}}</nowiki></code> &rarr; firstTemplateArg
** <code><nowiki>{{ExampleArgs|firstTemplateArg|secondTemplateArg}}</nowiki></code> &rarr; firstTemplateArg secondTemplateArg
* <code>parentFirst = true</code>
** <code><nowiki>{{ExampleArgs}}</nowiki></code> &rarr; firstInvokeArg
** <code><nowiki>{{ExampleArgs|firstTemplateArg}}</nowiki></code> &rarr; firstTemplateArg
** <code><nowiki>{{ExampleArgs|firstTemplateArg|secondTemplateArg}}</nowiki></code> &rarr; firstTemplateArg secondTemplateArg
 
=== Writing to the args table ===
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu