<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.mechsploit.me/index.php?action=history&amp;feed=atom&amp;title=Module%3AArguments%2Fdoc%2Fen</id>
	<title>Module:Arguments/doc/en - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.mechsploit.me/index.php?action=history&amp;feed=atom&amp;title=Module%3AArguments%2Fdoc%2Fen"/>
	<link rel="alternate" type="text/html" href="https://wiki.mechsploit.me/index.php?title=Module:Arguments/doc/en&amp;action=history"/>
	<updated>2026-04-08T13:12:23Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.mechsploit.me/index.php?title=Module:Arguments/doc/en&amp;diff=204&amp;oldid=prev</id>
		<title>MechsploWikiSysop: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.mechsploit.me/index.php?title=Module:Arguments/doc/en&amp;diff=204&amp;oldid=prev"/>
		<updated>2025-09-02T02:50:12Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 22:50, 1 September 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>MechsploWikiSysop</name></author>
	</entry>
	<entry>
		<id>https://wiki.mechsploit.me/index.php?title=Module:Arguments/doc/en&amp;diff=203&amp;oldid=prev</id>
		<title>mw&gt;FuzzyBot: Updating to match new version of source page</title>
		<link rel="alternate" type="text/html" href="https://wiki.mechsploit.me/index.php?title=Module:Arguments/doc/en&amp;diff=203&amp;oldid=prev"/>
		<updated>2023-03-09T22:29:42Z</updated>

		<summary type="html">&lt;p&gt;Updating to match new version of source page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;!--&lt;br /&gt;
--&amp;gt;{{#ifeq:{{SUBPAGENAME}}|doc||{{Documentation subpage}}}}&amp;lt;!--&lt;br /&gt;
--&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;!--&lt;br /&gt;
--&amp;gt;&amp;lt;/noinclude&amp;gt;{{#switch:&lt;br /&gt;
| =&lt;br /&gt;
&amp;lt;includeonly&amp;gt;{{Languages|Module:Arguments/doc}}&amp;lt;/includeonly&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add categories where indicated at the bottom of this page and interwikis at Wikidata --&amp;gt;&lt;br /&gt;
{{Shared Template Warning|Module:Arguments|Module:Arguments}}&lt;br /&gt;
{{Used in system}}&lt;br /&gt;
{{Module rating|release}}&lt;br /&gt;
{{Module rating|protected}}&lt;br /&gt;
&lt;br /&gt;
This module provides easy processing of arguments passed from {{Magic word|#invoke|...|ext=Scribunto|code=1|nowrap=1}}.&lt;br /&gt;
It is a meta-module, meant for use by other modules, and should not be called from {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}} directly.&lt;br /&gt;
Its features include:&lt;br /&gt;
&lt;br /&gt;
* Easy trimming of arguments and removal of blank arguments.&lt;br /&gt;
* Arguments can be passed by both the current frame and by the parent frame at the same time. (More details below.)&lt;br /&gt;
* Arguments can be passed in directly from another Lua module or from the debug console.&lt;br /&gt;
* Arguments are fetched as needed, which can help avoid (some) problems with {{xtag|ref}} tags.&lt;br /&gt;
* Most features can be customized.&lt;br /&gt;
&lt;br /&gt;
== Basic use ==&lt;br /&gt;
First, you need to load the module.&lt;br /&gt;
It contains one function, named &amp;lt;code&amp;gt;getArgs&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the most basic scenario, you can use &amp;lt;code&amp;gt;getArgs&amp;lt;/code&amp;gt; inside your main function.&lt;br /&gt;
The variable &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; is a table containing the arguments from {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}}.&lt;br /&gt;
(See below for details.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	-- Main module code goes here.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, the recommended practice is to use a function just for processing arguments from {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}}.&lt;br /&gt;
This means that if someone calls your module from another Lua module you don&amp;#039;t have to have a frame object available, which improves performance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	return p._main(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._main(args)&lt;br /&gt;
	-- Main module code goes here.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want multiple functions to use the arguments, and you also want them to be accessible from {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}}, you can use a wrapper function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local function makeInvokeFunc(funcName)&lt;br /&gt;
	return function (frame)&lt;br /&gt;
		local args = getArgs(frame)&lt;br /&gt;
		return p[funcName](args)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.func1 = makeInvokeFunc(&amp;#039;_func1&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
function p._func1(args)&lt;br /&gt;
	-- Code for the first function goes here.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.func2 = makeInvokeFunc(&amp;#039;_func2&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
function p._func2(args)&lt;br /&gt;
	-- Code for the second function goes here.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Options ===&lt;br /&gt;
The following options are available.&lt;br /&gt;
They are explained in the sections below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local args = getArgs(frame, {&lt;br /&gt;
	trim = false,&lt;br /&gt;
	removeBlanks = false,&lt;br /&gt;
	valueFunc = function (key, value)&lt;br /&gt;
		-- Code for processing one argument&lt;br /&gt;
	end,&lt;br /&gt;
	frameOnly = true,&lt;br /&gt;
	parentOnly = true,&lt;br /&gt;
	parentFirst = true,&lt;br /&gt;
	wrappers = {&lt;br /&gt;
		&amp;#039;Template:A wrapper template&amp;#039;,&lt;br /&gt;
		&amp;#039;Template:Another wrapper template&amp;#039;&lt;br /&gt;
	},&lt;br /&gt;
	readOnly = true,&lt;br /&gt;
	noOverwrite = true&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Trimming and removing blanks ===&lt;br /&gt;
Blank arguments often trip up coders new to converting MediaWiki templates to Lua.&lt;br /&gt;
In template syntax, blank strings and strings consisting only of whitespace are considered &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&lt;br /&gt;
However, in Lua, blank strings and strings consisting of whitespace are considered &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;.&lt;br /&gt;
This means that if you don&amp;#039;t pay attention to such arguments when you write your Lua modules, you might treat something as &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; that should actually be treated as &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&lt;br /&gt;
To avoid this, by default this module removes all blank arguments.&lt;br /&gt;
&lt;br /&gt;
Similarly, whitespace can cause problems when dealing with positional arguments.&lt;br /&gt;
Although whitespace is trimmed for named arguments coming from {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}}, it is preserved for positional arguments.&lt;br /&gt;
Most of the time this additional whitespace is not desired, so this module trims it off by default.&lt;br /&gt;
&lt;br /&gt;
However, sometimes you want to use blank arguments as input, and sometimes you want to keep additional whitespace.&lt;br /&gt;
This can be necessary to convert some templates exactly as they were written.&lt;br /&gt;
If you want to do this, you can set the &amp;lt;code&amp;gt;trim&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;removeBlanks&amp;lt;/code&amp;gt; arguments to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local args = getArgs(frame, {&lt;br /&gt;
	trim = false,&lt;br /&gt;
	removeBlanks = false&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Custom formatting of arguments ===&lt;br /&gt;
Sometimes you want to remove some blank arguments but not others, or perhaps you might want to put all of the positional arguments in lower case.&lt;br /&gt;
To do things like this you can use the &amp;lt;code&amp;gt;valueFunc&amp;lt;/code&amp;gt; option.&lt;br /&gt;
The input to this option must be a function that takes two parameters, &amp;lt;code&amp;gt;key&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;value&amp;lt;/code&amp;gt;, and returns a single value.&lt;br /&gt;
This value is what you will get when you access the field &amp;lt;code&amp;gt;key&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; table.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example 1:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
This function preserves whitespace for the first positional argument, but trims all other arguments and removes all other blank arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local args = getArgs(frame, {&lt;br /&gt;
	valueFunc = function (key, value)&lt;br /&gt;
		if key == 1 then&lt;br /&gt;
			return value&lt;br /&gt;
		elseif value then&lt;br /&gt;
			value = mw.text.trim(value)&lt;br /&gt;
			if value ~= &amp;#039;&amp;#039; then&lt;br /&gt;
				return value&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example 2:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
This function removes blank arguments and converts all arguments to lower case, but doesn&amp;#039;t trim whitespace from positional parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local args = getArgs(frame, {&lt;br /&gt;
	valueFunc = function (key, value)&lt;br /&gt;
		if not value then&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
		value = mw.ustring.lower(value)&lt;br /&gt;
		if mw.ustring.find(value, &amp;#039;%S&amp;#039;) then&lt;br /&gt;
			return value&lt;br /&gt;
		end&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|text=&lt;br /&gt;
The above functions will fail if passed input that is not of type &amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;nil&amp;lt;/code&amp;gt;.&lt;br /&gt;
This might be the case if you use the &amp;lt;code&amp;gt;getArgs&amp;lt;/code&amp;gt; function in the main function of your module, and that function is called by another Lua module.&lt;br /&gt;
In this case, you will need to check the type of your input.&lt;br /&gt;
This is not a problem if you are using a function specially for arguments from {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}} (i.e. you have &amp;lt;code&amp;gt;p.main&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;p._main&amp;lt;/code&amp;gt; functions, or something similar).&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Collapse top|1=Examples 1 and 2 with type checking}}&lt;br /&gt;
Example 1:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local args = getArgs(frame, {&lt;br /&gt;
	valueFunc = function (key, value)&lt;br /&gt;
		if key == 1 then&lt;br /&gt;
			return value&lt;br /&gt;
		elseif type(value) == &amp;#039;string&amp;#039; then&lt;br /&gt;
			value = mw.text.trim(value)&lt;br /&gt;
			if value ~= &amp;#039;&amp;#039; then&lt;br /&gt;
				return value&lt;br /&gt;
			else&lt;br /&gt;
				return nil&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			return value&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local args = getArgs(frame, {&lt;br /&gt;
	valueFunc = function (key, value)&lt;br /&gt;
		if type(value) == &amp;#039;string&amp;#039; then&lt;br /&gt;
			value = mw.ustring.lower(value)&lt;br /&gt;
			if mw.ustring.find(value, &amp;#039;%S&amp;#039;) then&lt;br /&gt;
				return value&lt;br /&gt;
			else&lt;br /&gt;
				return nil&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			return value&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{Collapse bottom}}&lt;br /&gt;
&lt;br /&gt;
Also, please note that the &amp;lt;code&amp;gt;valueFunc&amp;lt;/code&amp;gt; function is called more or less every time an argument is requested from the &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; table, so if you care about performance you should make sure you aren&amp;#039;t doing anything inefficient with your code.&lt;br /&gt;
&lt;br /&gt;
=== Frames and parent frames ===&lt;br /&gt;
&lt;br /&gt;
Arguments in the &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; table can be passed from the current frame or from its parent frame at the same time.&lt;br /&gt;
To understand what this means, it is easiest to give an example.&lt;br /&gt;
Let&amp;#039;s say that we have a module called &amp;lt;code&amp;gt;Module:ExampleArgs&amp;lt;/code&amp;gt;.&lt;br /&gt;
This module prints the first two positional arguments that it is passed.&lt;br /&gt;
&lt;br /&gt;
{{Collapse top|1=Module:ExampleArgs code}}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	return p._main(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._main(args)&lt;br /&gt;
	local first = args[1] or &amp;#039;&amp;#039;&lt;br /&gt;
	local second = args[2] or &amp;#039;&amp;#039;&lt;br /&gt;
	return first .. &amp;#039; &amp;#039; .. second&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{Collapse bottom}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Module:ExampleArgs&amp;lt;/code&amp;gt; is then called by &amp;lt;code&amp;gt;Template:ExampleArgs&amp;lt;/code&amp;gt;, which contains the code &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#invoke:ExampleArgs|main|firstInvokeArg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
This produces the result &amp;quot;firstInvokeArg&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Now if we were to call &amp;lt;code&amp;gt;Template:ExampleArgs&amp;lt;/code&amp;gt;, the following would happen:&lt;br /&gt;
&lt;br /&gt;
{{(!}} class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 50em; max-width: 100%;&amp;quot;&lt;br /&gt;
{{!}}-&lt;br /&gt;
! style=&amp;quot;width: 60%;&amp;quot; {{!}} Code&lt;br /&gt;
! style=&amp;quot;width: 40%;&amp;quot; {{!}} Result&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstInvokeArg&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs|firstTemplateArg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstInvokeArg&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs|firstTemplateArg|secondTemplateArg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstInvokeArg secondTemplateArg&lt;br /&gt;
{{!)}}&lt;br /&gt;
&lt;br /&gt;
There are three options you can set to change this behaviour: &amp;lt;code&amp;gt;frameOnly&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;parentOnly&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;parentFirst&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you set &amp;lt;code&amp;gt;frameOnly&amp;lt;/code&amp;gt; then only arguments passed from the current frame will be accepted; if you set &amp;lt;code&amp;gt;parentOnly&amp;lt;/code&amp;gt; then only arguments passed from the parent frame will be accepted; and if you set &amp;lt;code&amp;gt;parentFirst&amp;lt;/code&amp;gt; then arguments will be passed from both the current and parent frames, but the parent frame will have priority over the current frame.&lt;br /&gt;
Here are the results in terms of &amp;lt;code&amp;gt;Template:ExampleArgs&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;&amp;lt;code&amp;gt;frameOnly&amp;lt;/code&amp;gt;&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&lt;br /&gt;
{{(!}} class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 50em; max-width: 100%;&amp;quot;&lt;br /&gt;
{{!}}-&lt;br /&gt;
! style=&amp;quot;width: 60%;&amp;quot; {{!}} Code&lt;br /&gt;
! style=&amp;quot;width: 40%;&amp;quot; {{!}} Result&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstInvokeArg&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs|firstTemplateArg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstInvokeArg&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs|firstTemplateArg|secondTemplateArg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstInvokeArg&lt;br /&gt;
{{!)}}&lt;br /&gt;
&amp;lt;/dd&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;dt&amp;gt;&amp;lt;code&amp;gt;parentOnly&amp;lt;/code&amp;gt;&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&lt;br /&gt;
{{(!}} class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 50em; max-width: 100%;&amp;quot;&lt;br /&gt;
{{!}}-&lt;br /&gt;
! style=&amp;quot;width: 60%;&amp;quot; {{!}} Code&lt;br /&gt;
! style=&amp;quot;width: 40%;&amp;quot; {{!}} Result&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}}&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs|firstTemplateArg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstTemplateArg&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs|firstTemplateArg|secondTemplateArg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstTemplateArg secondTemplateArg&lt;br /&gt;
{{!)}}&lt;br /&gt;
&amp;lt;/dd&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;dt&amp;gt;&amp;lt;code&amp;gt;parentFirst&amp;lt;/code&amp;gt;&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&lt;br /&gt;
{{(!}} class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 50em; max-width: 100%;&amp;quot;&lt;br /&gt;
{{!}}-&lt;br /&gt;
! style=&amp;quot;width: 60%;&amp;quot; {{!}} Code&lt;br /&gt;
! style=&amp;quot;width: 40%;&amp;quot; {{!}} Result&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstInvokeArg&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs|firstTemplateArg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstTemplateArg&lt;br /&gt;
{{!}}-&lt;br /&gt;
{{!}} &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ExampleArgs|firstTemplateArg|secondTemplateArg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
{{!}} firstTemplateArg secondTemplateArg&lt;br /&gt;
{{!)}}&lt;br /&gt;
&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|text=&lt;br /&gt;
{{Ordered list&lt;br /&gt;
|1=&lt;br /&gt;
If you set both the &amp;lt;code&amp;gt;frameOnly&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;parentOnly&amp;lt;/code&amp;gt; options, the module won&amp;#039;t fetch any arguments at all from {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}}.&lt;br /&gt;
This is probably not what you want.&lt;br /&gt;
|2=&lt;br /&gt;
In some situations a parent frame may not be available, e.g. if &amp;lt;code&amp;gt;getArgs&amp;lt;/code&amp;gt; is passed the parent frame rather than the current frame.&lt;br /&gt;
In this case, only the frame arguments will be used (unless &amp;lt;code&amp;gt;parentOnly&amp;lt;/code&amp;gt; is set, in which case no arguments will be used) and the &amp;lt;code&amp;gt;parentFirst&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;frameOnly&amp;lt;/code&amp;gt; options will have no effect.&lt;br /&gt;
}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Wrappers ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;wrappers&amp;lt;/code&amp;gt; option is used to specify a limited number of templates as &amp;#039;&amp;#039;wrapper templates&amp;#039;&amp;#039;, that is, templates whose only purpose is to call a module.&lt;br /&gt;
If the module detects that it is being called from a wrapper template, it will only check for arguments in the parent frame; otherwise it will only check for arguments in the frame passed to &amp;lt;code&amp;gt;getArgs&amp;lt;/code&amp;gt;.&lt;br /&gt;
This allows modules to be called by either {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}} or through a wrapper template without the loss of performance associated with having to check both the frame and the parent frame for each argument lookup.&lt;br /&gt;
&lt;br /&gt;
For example, the only content of {{tlx|Navbox}} (excluding content in {{tag|noinclude}} tags) is &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#invoke:Navbox|navbox}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
There is no point in checking the arguments passed directly to the {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}} statement for this template, as no arguments will ever be specified there.&lt;br /&gt;
We can avoid checking arguments passed to {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}} by using the &amp;lt;code&amp;gt;parentOnly&amp;lt;/code&amp;gt; option, but if we do this then {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}} will not work from other pages either.&lt;br /&gt;
If this were the case, then {{tmpl|0={{para|text|$1}}|Some text}} in the code {{tmpl|0={{tlc|&amp;lt;nowiki&amp;gt;#invoke:Navbox&amp;lt;/nowiki&amp;gt;|navbox|3=text=$1}}|Some text}} would be ignored completely, no matter what page it was used from.&lt;br /&gt;
By using the &amp;lt;code&amp;gt;wrappers&amp;lt;/code&amp;gt; option to specify [[Template:Navbox]] as a wrapper, we can make {{tmpl|0={{tlc|&amp;lt;nowiki&amp;gt;#invoke:Navbox&amp;lt;/nowiki&amp;gt;|main|3=text=$1}}|Some text}} work from most pages, while still not requiring that the module check for arguments on the [[Template:Navbox]] page itself.&lt;br /&gt;
&lt;br /&gt;
Wrappers can be specified either as a string, or as an array of strings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local args = getArgs(frame, {&lt;br /&gt;
	wrappers = &amp;#039;Template:Wrapper template&amp;#039;&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local args = getArgs(frame, {&lt;br /&gt;
	wrappers = {&lt;br /&gt;
		&amp;#039;Template:Wrapper 1&amp;#039;,&lt;br /&gt;
		&amp;#039;Template:Wrapper 2&amp;#039;,&lt;br /&gt;
		-- Any number of wrapper templates can be added here.&lt;br /&gt;
	}&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|text=&lt;br /&gt;
{{Ordered list&lt;br /&gt;
|1=&lt;br /&gt;
The module will automatically detect if it is being called from a wrapper template&amp;#039;s &amp;lt;code&amp;gt;/sandbox&amp;lt;/code&amp;gt; subpage, so there is no need to specify sandbox pages explicitly.&lt;br /&gt;
|2=&lt;br /&gt;
The &amp;lt;code&amp;gt;wrappers&amp;lt;/code&amp;gt; option effectively changes the default of the &amp;lt;code&amp;gt;frameOnly&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;parentOnly&amp;lt;/code&amp;gt; options.&lt;br /&gt;
If, for example, &amp;lt;code&amp;gt;parentOnly&amp;lt;/code&amp;gt; were explicitly set to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;wrappers&amp;lt;/code&amp;gt; set, calls via wrapper templates would result in both frame and parent arguments being loaded, though calls not via wrapper templates would result in only frame arguments being loaded.&lt;br /&gt;
|3=&lt;br /&gt;
If the &amp;lt;code&amp;gt;wrappers&amp;lt;/code&amp;gt; option is set and no parent frame is available, the module will always get the arguments from the frame passed to &amp;lt;code&amp;gt;getArgs&amp;lt;/code&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Writing to the &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; table ===&lt;br /&gt;
Sometimes it can be useful to write new values to the &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; table.&lt;br /&gt;
This is possible with the default settings of this module.&lt;br /&gt;
(However, bear in mind that it is usually better coding style to create a new table with your new values and copy arguments from the &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; table as needed.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
args.foo = &amp;#039;some value&amp;#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is possible to alter this behaviour with the &amp;lt;code&amp;gt;readOnly&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;noOverwrite&amp;lt;/code&amp;gt; options.&lt;br /&gt;
If &amp;lt;code&amp;gt;readOnly&amp;lt;/code&amp;gt; is set then it is not possible to write any values to the &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; table at all.&lt;br /&gt;
If &amp;lt;code&amp;gt;noOverwrite&amp;lt;/code&amp;gt; is set, then it is possible to add new values to the table, but it is not possible to add a value if it would overwrite any arguments that are passed from {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}}.&lt;br /&gt;
&lt;br /&gt;
=== Ref tags ===&lt;br /&gt;
This module uses [[mw:Special:MyLanguage/Extension:Scribunto/Lua reference manual#Metatables|metatables]] to fetch arguments from {{tlc|&amp;lt;nowiki&amp;gt;#invoke:...&amp;lt;/nowiki&amp;gt;}}.&lt;br /&gt;
This allows access to both the frame arguments and the parent frame arguments without using the &amp;lt;code&amp;gt;pairs()&amp;lt;/code&amp;gt; function.&lt;br /&gt;
This can help if your module might be passed {{xtag|ref}} tags as input.&lt;br /&gt;
&lt;br /&gt;
As soon as {{xtag|ref}} tags are accessed from Lua, they are processed by the MediaWiki software and the reference will appear in the reference list at the bottom of the article.&lt;br /&gt;
If your module proceeds to omit the reference tag from the output, you will end up with a phantom reference - a reference that appears in the reference list, but no number that links to it.&lt;br /&gt;
This has been a problem with modules that use &amp;lt;code&amp;gt;pairs()&amp;lt;/code&amp;gt; to detect whether to use the arguments from the frame or the parent frame, as those modules automatically process every available argument.&lt;br /&gt;
&lt;br /&gt;
This module solves this problem by allowing access to both frame and parent frame arguments, while still only fetching those arguments when it is necessary.&lt;br /&gt;
The problem will still occur if you use &amp;lt;code&amp;gt;pairs(args)&amp;lt;/code&amp;gt; elsewhere in your module, however.&lt;br /&gt;
&lt;br /&gt;
=== Known limitations ===&lt;br /&gt;
The use of metatables also has its downsides.&lt;br /&gt;
Most of the normal Lua table tools won&amp;#039;t work properly on the &amp;lt;code&amp;gt;args&amp;lt;/code&amp;gt; table, including the &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt; operator, the &amp;lt;code&amp;gt;next()&amp;lt;/code&amp;gt; function, and the functions in the &amp;lt;code&amp;gt;table&amp;lt;/code&amp;gt; library.&lt;br /&gt;
If using these is important for your module, you should use your own argument processing function instead of this module.&lt;br /&gt;
&lt;br /&gt;
== Tests ==&lt;br /&gt;
{{ModuleQuality}}&lt;br /&gt;
&amp;lt;includeonly&amp;gt;{{Sandbox other||&lt;br /&gt;
&amp;lt;!-- Categories below this line; interwikis at Wikidata --&amp;gt;&lt;br /&gt;
[[Category:Lua metamodules{{#translation:}}]]&lt;br /&gt;
}}&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Module documentation pages{{#translation:}}]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
| #default=&lt;br /&gt;
  {{#invoke:Template translation|renderTranslatedTemplate|template=Module:Arguments/doc|noshift=1|uselang={{int:lang}}}}&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>mw&gt;FuzzyBot</name></author>
	</entry>
</feed>