Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Arguments/doc/cs

From Mechsploit.me Wiki
Revision as of 22:50, 1 September 2025 by MechsploWikiSysop (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

{{#ifeq:cs|doc||{{#ifeq:cs |doc

    | 

{{#ifeq:show |show

|

        }}{{#if: |
         |   {{#ifexist:Module:Arguments/doc
                  | [[Category:{{#switch:Module |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]]
                  | 
                 }}
        }}
    | 
   }}}}{{#switch:

| =

Template:Shared Template Warning Template:Used in system Template:Module rating Template:Module rating

Tento modul umožňuje snadné zpracování argumentů předávaných z Template:Magic word. Je to metamodul určený pro použití jinými moduly a neměl by být volán přímo z Template:Tlc. Mezi jeho vlastnosti patří:

  • Snadné ořezávání argumentů a odstraňování prázdných argumentů.
  • Argumenty mohou být předány současně aktuálním rámcem i nadřazeným rámcem. (Další podrobnosti níže.)
  • Argumenty lze předávat přímo z jiného modulu Lua nebo z ladicí konzole.
  • Argumenty se načítají podle potřeby, což může pomoci vyhnout se (některým) problémům se značkami Template:Xtag.
  • Většinu funkcí lze přizpůsobit.

Základní použití

Nejprve je třeba načíst modul. Obsahuje jednu funkci s názvem getArgs.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs </syntaxhighlight>

V nejzákladnějším scénáři můžete v hlavní funkci použít getArgs. Proměnná args je tabulka obsahující argumenty z Template:Tlc. (Další podrobnosti najdete níže.)

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) -- Zde je kód hlavního modulu. end

return p </syntaxhighlight>

Doporučená praxe je však použít funkci pouze pro zpracování argumentů od Template:Tlc. To znamená, že pokud někdo zavolá váš modul z jiného modulu Lua, nemusíte mít k dispozici rámový objekt, což zlepšuje výkon.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) return p._main(args) end

function p._main(args) -- Zde je kód hlavního modulu. end

return p </syntaxhighlight>

Pokud chcete, aby argumenty používalo více funkcí, a také chcete, aby byly přístupné z Template:Tlc, můžete použít funkci wrapper.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs

local p = {}

local function makeInvokeFunc(funcName) return function (frame) local args = getArgs(frame) return p[funcName](args) end end

p.func1 = makeInvokeFunc('_func1')

function p._func1(args) -- Zde je kód pro první funkci. end

p.func2 = makeInvokeFunc('_func2')

function p._func2(args) -- Zde je kód pro druhou funkci. end

return p </syntaxhighlight>

Možnosti

K dispozici jsou následující možnosti. Jsou vysvětleny v následujících částech.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { trim = false, removeBlanks = false, valueFunc = function (key, value) -- Kód pro zpracování jednoho argumentu end, frameOnly = true, parentOnly = true, parentFirst = true, wrappers = { 'Template:A wrapper template', 'Template:Another wrapper template' }, readOnly = true, noOverwrite = true }) </syntaxhighlight>

Ořezávání a odstraňování polotovarů

Prázdné argumenty často podrazí kodéry, které jsou novým převodem šablon MediaWiki na Lua. V syntaxi šablony jsou prázdné řetězce a řetězce obsahující pouze mezery považovány za false. V Lua jsou však prázdné řetězce a řetězce obsahující mezery považovány za true. To znamená, že pokud těmto argumentům při psaní svých Lua modulů nevěnujete pozornost, můžete s něčím zacházet jako s true, s čím by ve skutečnosti mělo být zacházeno jako s false. Aby se tomu zabránilo, ve výchozím nastavení tento modul odstraňuje všechny prázdné argumenty.

Podobně mohou bílé znaky způsobit problémy při práci s pozičními argumenty. Přestože jsou mezery oříznuty pro pojmenované argumenty pocházející z Template:Tlc, jsou zachovány pro poziční argumenty. Většinu času není tato další mezera žádoucí, takže tento modul je ve výchozím nastavení ořízne.

Někdy však chcete jako vstup použít prázdné argumenty a někdy chcete ponechat další mezery. To může být nezbytné pro převod některých šablon přesně tak, jak byly napsány. Pokud to chcete udělat, můžete nastavit argumenty trim a removeBlanks na false.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { trim = false, removeBlanks = false }) </syntaxhighlight>

Vlastní formátování argumentů

Někdy chcete odstranit některé prázdné argumenty, ale ne jiné, nebo možná budete chtít umístit všechny poziční argumenty malými písmeny. Chcete-li dělat věci, jako je tato, můžete použít možnost valueFunc. Vstupem této možnosti musí být funkce, která přebírá dva parametry, key a value, a vrací jedinou hodnotu. Tato hodnota je to, co získáte, když vstoupíte do pole key v tabulce args.

Příklad 1: Tato funkce zachová mezery pro první poziční argument, ale ořízne všechny ostatní argumenty a odstraní všechny ostatní prázdné argumenty.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if key == 1 then return value elseif value then value = mw.text.trim(value) if value ~= then return value end end return nil end }) </syntaxhighlight>

Příklad 2: Tato funkce odstraní prázdné argumenty a převede všechny argumenty na malá písmena, ale neořízne mezery od pozičních parametrů.

<syntaxhighlight lang="lua"> 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 }) </syntaxhighlight>

Template:Note

{{#if: | }}
Příklady 1 a 2 s kontrolou typu
{{#if:|{{{2}}}|<translate> The following is a closed debate.</translate> Template:Strong}}

Příklad 1: <syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if key == 1 then return value elseif type(value) == 'string' then value = mw.text.trim(value) if value ~= then return value else return nil end else return value end end }) </syntaxhighlight>

Příklad 2: <syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if type(value) == 'string' then value = mw.ustring.lower(value) if mw.ustring.find(value, '%S') then return value else return nil end else return value end end }) </syntaxhighlight>

Pamatujte také, že funkce valueFunc je volána víceméně pokaždé, když je požadován argument z tabulky args, takže pokud vám záleží na výkonu, měli byste se ujistit, že se svým kódem neděláte nic neefektivního.

Rámce a nadřazené rámce

Argumenty v tabulce args lze současně předávat z aktuálního rámce nebo z jeho nadřazeného rámce. Abychom pochopili, co to znamená, je nejjednodušší uvést příklad. Řekněme, že máme modul nazvaný Module:ExampleArgs. Tento modul vypíše první dva poziční argumenty, které jsou předány.

{{#if: | }}
kód Module:ExampleArgs
{{#if:|{{{2}}}|<translate> The following is a closed debate.</translate> Template:Strong}}

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) return p._main(args) end

function p._main(args) local first = args[1] or local second = args[2] or return first .. ' ' .. second end

return p </syntaxhighlight>

Module:ExampleArgs je pak volán Template:ExampleArgs, který obsahuje kód {{#invoke:ExampleArgs|main|firstInvokeArg}}. Výsledkem je "firstInvokeArg".

Pokud bychom nyní zavolali Template:ExampleArgs, stalo by se následující:

Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Kód ! style="width: 40%;" | Výsledek |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstInvokeArg secondTemplateArg Template:!)

Pro změnu tohoto chování můžete nastavit tři možnosti: frameOnly, parentOnly a parentFirst. Pokud nastavíte frameOnly, budou přijaty pouze argumenty předané z aktuálního rámce. Pokud nastavíte parentOnly, budou přijaty pouze argumenty předané z nadřazeného rámce. A pokud nastavíte parentFirst, budou argumenty předány z aktuálního i nadřazeného snímku, ale nadřazený snímek bude mít prioritu před aktuálním snímkem. Zde jsou výsledky na Template:ExampleArgs:

frameOnly
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Kód ! style="width: 40%;" | Výsledek |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstInvokeArg Template:!)
parentOnly
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Kód ! style="width: 40%;" | Výsledek |- | {{ExampleArgs}} | |- | {{ExampleArgs|firstTemplateArg}} | firstTemplateArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstTemplateArg secondTemplateArg Template:!)
parentFirst
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Kód ! style="width: 40%;" | Výsledek |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstTemplateArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstTemplateArg secondTemplateArg Template:!)

Template:Note

Wrappers

Volba wrappers se používá k určení omezeného počtu šablon jako šablony obalů, tedy šablon, jejichž jediným účelem je volání modulu. Pokud modul zjistí, že je volán ze šablony wrapperu, zkontroluje pouze argumenty v nadřazeném rámci. Jinak bude kontrolovat pouze argumenty v rámci předaném getArgs. To umožňuje modulům volat buď pomocí Template:Tlc nebo prostřednictvím šablony wrapperu, aniž by došlo ke ztrátě výkonu spojené s nutností kontrolovat rámec i nadřazený rámec pro každé vyhledávání argumentů.

Například jediný obsah {{Navbox}} (s výjimkou obsahu ve značkách Template:Tag) je {{#invoke:Navbox|navbox}}. Nemá smysl kontrolovat argumenty předávané přímo příkazu Template:Tlc pro tuto šablonu, protože tam nikdy nebudou zadány žádné argumenty. Můžeme se vyhnout kontrole argumentů předávaných do Template:Tlc použitím možnosti parentOnly, ale pokud to uděláme, Template:Tlc nebude fungovat ani z jiných stránek. Pokud by tomu tak bylo, pak by Template:Tmpl v kódu Template:Tmpl byl zcela ignorován, bez ohledu na to, z jaké stránky byl použit. Použitím možnosti wrappers k určení Template:Navbox jako obalu můžeme zajistit, aby Template:Tmpl fungovalo na většině stránek, aniž by bylo nutné, aby modul kontroloval argumenty na samotné stránce Template:Navbox.

Wrappers lze zadat buď jako řetězec, nebo jako pole řetězců.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { wrappers = 'Template:Wrapper template' }) </syntaxhighlight>

<syntaxhighlight lang="lua"> local args = getArgs(frame, { wrappers = { 'Template:Wrapper 1', 'Template:Wrapper 2', -- Zde lze přidat libovolný počet šablon wrapper. } }) </syntaxhighlight>

Template:Note

Zápis do args tabulky

Někdy může být užitečné zapsat nové hodnoty do tabulky args. To je možné s výchozím nastavením tohoto modulu. (Mějte však na paměti, že obvykle je lepší styl kódování vytvořit novou tabulku s novými hodnotami a podle potřeby zkopírovat argumenty z tabulky args.)

<syntaxhighlight lang="lua"> args.foo = 'nějaká hodnota' </syntaxhighlight>

Toto chování je možné změnit pomocí možností readOnly a noOverwrite. Pokud je nastaveno readOnly, není možné do tabulky args zapisovat vůbec žádné hodnoty. Pokud je nastaveno noOverwrite, pak je možné do tabulky přidávat nové hodnoty, ale není možné přidat hodnotu, pokud by to přepsalo nějaké argumenty předávané z Template:Tlc.

Tagy Ref

Tento modul používá metatables k načítání argumentů z Template:Tlc. To umožňuje přístup k argumentům rámce i argumentům nadřazeného rámce bez použití funkce pairs(). To může pomoci, pokud vašemu modulu mohou být předány tagy Template:Xtag jako vstup.

Jakmile jsou tagy Template:Xtag zpřístupněny z Lua, jsou zpracovány softwarem MediaWiki a reference se objeví v seznamu referencí ve spodní části článku. Pokud váš modul vynechá referenční značku z výstupu, skončíte s fantomovou referencí – referencí, která se objeví v seznamu referencí, ale žádné číslo, které by na ni odkazovalo. To byl problém s moduly, které používají pairs() ke zjištění, zda použít argumenty z rámce nebo nadřazeného rámce, protože tyto moduly automaticky zpracovávají každý dostupný argument.

Tento modul řeší tento problém tím, že umožňuje přístup k argumentům rámce i nadřazeného rámce, přičemž tyto argumenty načítá pouze tehdy, když je to nutné. Problém však bude stále nastávat, pokud jinde ve svém modulu použijete pairs(args).

Známá omezení

Používání metatabulek má i své stinné stránky. Většina běžných nástrojů tabulky Lua nebude správně fungovat v tabulce args, včetně operátoru #, funkce next() a funkcí v knihovně table. Pokud je jejich použití pro váš modul důležité, měli byste místo tohoto modulu použít svou vlastní funkci zpracování argumentů.

Testy

Template:ModuleQuality

| #default=

 {{#switch:

| = Template:Languages Template:Shared Template Warning Template:Used in system Template:Module rating Template:Module rating

This module provides easy processing of arguments passed from Template:Magic word. It is a meta-module, meant for use by other modules, and should not be called from Template:Tlc directly. Its features include:

  • Easy trimming of arguments and removal of blank arguments.
  • Arguments can be passed by both the current frame and by the parent frame at the same time. (More details below.)
  • Arguments can be passed in directly from another Lua module or from the debug console.
  • Arguments are fetched as needed, which can help avoid (some) problems with Template:Xtag tags.
  • Most features can be customized.

Basic use

First, you need to load the module. It contains one function, named getArgs.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs </syntaxhighlight>

In the most basic scenario, you can use getArgs inside your main function. The variable args is a table containing the arguments from Template:Tlc. (See below for details.)

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) -- Main module code goes here. end

return p </syntaxhighlight>

However, the recommended practice is to use a function just for processing arguments from Template:Tlc. This means that if someone calls your module from another Lua module you don't have to have a frame object available, which improves performance.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) return p._main(args) end

function p._main(args) -- Main module code goes here. end

return p </syntaxhighlight>

If you want multiple functions to use the arguments, and you also want them to be accessible from Template:Tlc, you can use a wrapper function.

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs

local p = {}

local function makeInvokeFunc(funcName) return function (frame) local args = getArgs(frame) return p[funcName](args) end end

p.func1 = makeInvokeFunc('_func1')

function p._func1(args) -- Code for the first function goes here. end

p.func2 = makeInvokeFunc('_func2')

function p._func2(args) -- Code for the second function goes here. end

return p </syntaxhighlight>

Options

The following options are available. They are explained in the sections below.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { trim = false, removeBlanks = false, valueFunc = function (key, value) -- Code for processing one argument end, frameOnly = true, parentOnly = true, parentFirst = true, wrappers = { 'Template:A wrapper template', 'Template:Another wrapper template' }, readOnly = true, noOverwrite = true }) </syntaxhighlight>

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 Template:Tlc, 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 trim and removeBlanks arguments to false.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { trim = false, removeBlanks = false }) </syntaxhighlight>

Custom formatting of arguments

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. To do things like this you can use the valueFunc option. The input to this option must be a function that takes two parameters, key and value, and returns a single value. This value is what you will get when you access the field key in the args table.

Example 1: This function preserves whitespace for the first positional argument, but trims all other arguments and removes all other blank arguments.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if key == 1 then return value elseif value then value = mw.text.trim(value) if value ~= then return value end end return nil end }) </syntaxhighlight>

Example 2: This function removes blank arguments and converts all arguments to lower case, but doesn't trim whitespace from positional parameters.

<syntaxhighlight lang="lua"> 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 }) </syntaxhighlight>

Template:Note

{{#if: | }}
Examples 1 and 2 with type checking
{{#if:|{{{2}}}|<translate> The following is a closed debate.</translate> Template:Strong}}

Example 1: <syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if key == 1 then return value elseif type(value) == 'string' then value = mw.text.trim(value) if value ~= then return value else return nil end else return value end end }) </syntaxhighlight>

Example 2: <syntaxhighlight lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if type(value) == 'string' then value = mw.ustring.lower(value) if mw.ustring.find(value, '%S') then return value else return nil end else return value end end }) </syntaxhighlight>

Also, please note that the valueFunc function is called more or less every time an argument is requested from the args table, so if you care about performance you should make sure you aren't doing anything inefficient with your code.

Frames and parent frames

Arguments in the args 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 Module:ExampleArgs. This module prints the first two positional arguments that it is passed.

{{#if: | }}
Module:ExampleArgs code
{{#if:|{{{2}}}|<translate> The following is a closed debate.</translate> Template:Strong}}

<syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {}

function p.main(frame) local args = getArgs(frame) return p._main(args) end

function p._main(args) local first = args[1] or local second = args[2] or return first .. ' ' .. second end

return p </syntaxhighlight>

Module:ExampleArgs is then called by Template:ExampleArgs, which contains the code {{#invoke:ExampleArgs|main|firstInvokeArg}}. This produces the result "firstInvokeArg".

Now if we were to call Template:ExampleArgs, the following would happen:

Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstInvokeArg secondTemplateArg Template:!)

There are three options you can set to change this behaviour: frameOnly, parentOnly and parentFirst. If you set frameOnly then only arguments passed from the current frame will be accepted; if you set parentOnly then only arguments passed from the parent frame will be accepted; and if you set parentFirst 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 Template:ExampleArgs:

frameOnly
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstInvokeArg Template:!)
parentOnly
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | {{ExampleArgs}} | |- | {{ExampleArgs|firstTemplateArg}} | firstTemplateArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstTemplateArg secondTemplateArg Template:!)
parentFirst
Template:(! class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | {{ExampleArgs}} | firstInvokeArg |- | {{ExampleArgs|firstTemplateArg}} | firstTemplateArg |- | {{ExampleArgs|firstTemplateArg|secondTemplateArg}} | firstTemplateArg secondTemplateArg Template:!)

Template:Note

Wrappers

The wrappers option is used to specify a limited number of templates as wrapper templates, that is, templates whose only purpose is to call a module. 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 getArgs. This allows modules to be called by either Template:Tlc 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.

For example, the only content of {{Navbox}} (excluding content in Template:Tag tags) is {{#invoke:Navbox|navbox}}. There is no point in checking the arguments passed directly to the Template:Tlc statement for this template, as no arguments will ever be specified there. We can avoid checking arguments passed to Template:Tlc by using the parentOnly option, but if we do this then Template:Tlc will not work from other pages either. If this were the case, then Template:Tmpl in the code Template:Tmpl would be ignored completely, no matter what page it was used from. By using the wrappers option to specify Template:Navbox as a wrapper, we can make Template:Tmpl work from most pages, while still not requiring that the module check for arguments on the Template:Navbox page itself.

Wrappers can be specified either as a string, or as an array of strings.

<syntaxhighlight lang="lua"> local args = getArgs(frame, { wrappers = 'Template:Wrapper template' }) </syntaxhighlight>

<syntaxhighlight lang="lua"> local args = getArgs(frame, { wrappers = { 'Template:Wrapper 1', 'Template:Wrapper 2', -- Any number of wrapper templates can be added here. } }) </syntaxhighlight>

Template:Note

Writing to the args table

Sometimes it can be useful to write new values to the args table. This is possible with the default settings of this module. (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 args table as needed.)

<syntaxhighlight lang="lua"> args.foo = 'some value' </syntaxhighlight>

It is possible to alter this behaviour with the readOnly and noOverwrite options. If readOnly is set then it is not possible to write any values to the args table at all. If noOverwrite 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 Template:Tlc.

Ref tags

This module uses metatables to fetch arguments from Template:Tlc. This allows access to both the frame arguments and the parent frame arguments without using the pairs() function. This can help if your module might be passed Template:Xtag tags as input.

As soon as Template:Xtag 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. 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. This has been a problem with modules that use pairs() to detect whether to use the arguments from the frame or the parent frame, as those modules automatically process every available argument.

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. The problem will still occur if you use pairs(args) elsewhere in your module, however.

Known limitations

The use of metatables also has its downsides. Most of the normal Lua table tools won't work properly on the args table, including the # operator, the next() function, and the functions in the table library. If using these is important for your module, you should use your own argument processing function instead of this module.

Tests

Template:ModuleQuality {{safesubst:#if:{{safesubst:#ifeq:cs|sandbox|1}}{{safesubst:#ifeq:cs|doc|1}}|| }} | #default=

 Lua error: expandTemplate: template loop detected.

}} }}