Final Fantasy Wiki
m (+)
m (Bot: Changing template: See Also)
 
(29 intermediate revisions by 4 users not shown)
Line 5: Line 5:
   
 
Module list:
 
Module list:
{{See Also|User:Technobliterator/Luastuff}}
+
{{See|User:Technobliterator/Luastuff}}
 
;Auxiliary
 
;Auxiliary
 
*[[Module:Sandsea]] - says hello world and provides test area.
 
*[[Module:Sandsea]] - says hello world and provides test area.
Line 13: Line 13:
 
*[[Module:Talk]] - nowhere near done and probably buggy as hell
 
*[[Module:Talk]] - nowhere near done and probably buggy as hell
 
**[[Module:Talk/Tables]] - CSS and param tables for Talk
 
**[[Module:Talk/Tables]] - CSS and param tables for Talk
*[[Module:Gallery]] - to replace {{tl|gallery}} and especially expensive galleries
+
*<nowiki>[[Module:Gallery]] - to replace {{tl|gallery}} and especially expensive galleries</nowiki>
 
;Metatemplate and parserfunction translations
 
;Metatemplate and parserfunction translations
 
*[[Module:WikiFunctions]] - a possible replacement to parser functions, incomplete and untested
 
*[[Module:WikiFunctions]] - a possible replacement to parser functions, incomplete and untested
Line 22: Line 22:
 
Feel free to update the above. Also, plz respond in this thread when making major changes to modules, so we don't either (a) have three people working on the same thing or (b) have one person do something that no one else understands.
 
Feel free to update the above. Also, plz respond in this thread when making major changes to modules, so we don't either (a) have three people working on the same thing or (b) have one person do something that no one else understands.
 
}}
 
}}
 
==Invokables==
 
===[[Module:Tl|Tl]]===
 
Function: <code>new</code>
 
 
For use with {{tl|tl}}. Takes value in first parameter and distinguishes <code>subst</code>, <code>#invoke</code>, namespace, page name, and non-function values (in the case of MediaWiki functions which use colons for the first value), and also where to link as some functions link to help pages, while others link nowhere.
 
 
All following parameters count as display parameters. {{tl|tl}} only includes one additional parameter therefore {{tl|!}} have to be employed. It is still recommended that users use the {{tl|tl}} template, though using {{tl|#invoke:tl|new}} is advantageous on documentation pages.
 
 
Examples:
 
:{{#invoke:tl|new|#invoke:tl|new|A}} → {{#invoke:tl|new|A}}
 
:{{#invoke:tl|new|#invoke:tl|new|-|left}} → {{#invoke:tl|new|-|left}}
 
:{{#invoke:tl|new|#invoke:tl|new|#expr:5+5}} → {{#invoke:tl|new|#expr:5+5}}
 
:{{#invoke:tl|new|#invoke:tl|new|#invoke}} → {{#invoke:tl|new|#invoke}}
 
:{{#invoke:tl|new|#invoke:tl|new|ifstring|Dog|d|case{{tl|1==}}sensitive}} → {{#invoke:tl|new|ifstring|Dog|d|case{{=}}sensitive}}
 
 
===[[Module:Codename|Codename]]===
 
A server-side stored version of the system hosted in JavaScript. This allows for queries and comparisons. For example {{#invoke:tl|new|#ifeq:{{#invoke:tl|new|#invoke:Codename|rel|FFI|full}}|Final Fantasy|success}} becomes "{{#ifeq:{{#invoke:Codename|rel|FFI|full}}|Final Fantasy|success}}".
 
 
Imagine the possibilities! One use returns values in a similar manner to how the [[Help:JavaScript|JavaScript]]-backed HTML class "variable-output" works ({{tag|span|class=variable-output|rel.FFI.full}} becomes "<span class="variable-output">rel.FFI.full</span>").
 
 
One thing that can be done is using the colors outside of their normal text color and background color scenario.
 
 
{{tag|span|style=background:{{#invoke:tl|new|#invoke:Codename|rel|FFX|a|background}};border:2px solid {{#invoke:tl|new|#invoke:Codename|rel|FFX|b|background}}|{{#invoke:tl|new|#invoke:Codename|rel|FFX|full}}}} -> <span style="background:{{#invoke:Codename|rel|FFX|a|background}};border:2px solid {{#invoke:Codename|rel|FFX|b|background}}">{{#invoke:Codename|rel|FFX|full}}</span>
 
 
Another way in which the module can be used is <code>lookup</code> which allows a value to be searched for in a specific sub-property and returns matching codenames.
 
 
:{{#invoke:tl|new|#invoke:Codename|lookup|rel|full|Final Fantasy}} -> {{#invoke:Codename|lookup|rel|full|Final Fantasy}}
 
 
If the lookup matches multiple codenames then it returns an array. One can return a single member of the array by attaching a number, so:
 
 
:{{#invoke:tl|new|#invoke:Codename|lookup|rel|a|color|black}} -> {{#invoke:Codename|lookup|rel|a|color|black}}
 
 
:{{#invoke:tl|new|#invoke:Codename|lookup|rel|a|color|4|black}} -> {{#invoke:Codename|lookup|rel|a|color|4|black}}
 
 
Although this feature does not serve much purpose because the order of array members are in an arbitrary order, and a user will unlikely be searching for a specific codename when using it, and even if they were- catching it by specification of number would be worrying.
 
 
===[[Module:WikiFunctions|WikiFunctions]]===
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|<code>ifstring</code>
 
|<code>string</code><br/><code>search</code><br/><code>true</code> - Value if true<br/><code>false</code> - Value if false (default: blank string)
 
|{{#invoke:tl|new|#invoke:WikiFunctions|ifstring|All|B|C}} -> <strong>{{#invoke:WikiFunctions|ifstring|All|B|C}}</strong><br/>{{#invoke:tl|new|#invoke:WikiFunctions|ifstring|All|a|C|D}} -> <strong>{{#invoke:WikiFunctions|ifstring|All|a|C|D}}</strong><br/>{{#invoke:tl|new|#invoke:WikiFunctions|ifstring|All|A|C|D}} -> <strong>{{#invoke:WikiFunctions|ifstring|All|A|C|D}}</strong>
 
|Tests if <code>string</code> contains <code>search</code> string and prints <code>true</code> or </code>false</code> string accordingly.
 
|-
 
|<code>ifnum</code>
 
|<code>string</code><br/><code>true</code> - Value if true<br/><code>false</code> - Value if false (default: blank string)
 
|{{#invoke:tl|new|#invoke:WikiFunctions|ifnum|A|B}} -> <strong>{{#invoke:WikiFunctions|ifnum|A|B}}</strong><br/>{{#invoke:tl|new|#invoke:WikiFunctions|ifnum|e|B|C}} -> <strong>{{#invoke:WikiFunctions|ifnum|e|B|C}}</strong><br/>{{#invoke:tl|new|#invoke:WikiFunctions|ifnum|0|B|C}} -> <strong>{{#invoke:WikiFunctions|ifnum|0|B|C}}</strong>
 
|Tests if <code>string</code> evaluates as a number and prints <code>true</code> or </code>false</code> string accordingly.
 
|-
 
|<code>expr</code>
 
|<code>expression</code>
 
|{{#invoke:tl|new|#invoke:WikiFunctions|expr|1+5*6}} -> <strong>{{#invoke:WikiFunctions|expr|1+5*6}}</strong><br/>{{#invoke:tl|new|#invoke:WikiFunctions|expr|2<3}} -> <strong>{{#invoke:WikiFunctions|expr|2<3}}</strong><br/>{{#invoke:tl|new|#invoke:WikiFunctions|expr|2004 % 4 {{=}}{{=}} 0 and (2004 % 100 ~{{=}} 0 or 2004 % 400 {{=}}{{=}} 0)}} -> <strong>{{#invoke:WikiFunctions|expr|1=2004 % 4 == 0 and (2004 % 100 ~= 0 or 2004 % 400 == 0)}}</strong>
 
|Prints evaluated <code>expression</code>. Uses Lua equation syntax.
 
|-
 
|<code>arraymap</code>
 
|<code>array</code> - Delimiter separated string<br/><code>delimiter</code><br/><code>variable</code> - String to replace<br/><code>formula</code> - Recurring string contains variable<br/><code>separator</code> - String appearing after each <code>formula</code> instance (default: empty string)
 
|{{#invoke:tl|new|#invoke:WikiFunctions|arraymap|A@B@C@D|@|{X}|.{X}.}} → '''{{#invoke:WikiFunctions|arraymap|A@B@C@D|@|{X}|.{X}.}}'''<br/>{{#invoke:tl|new|#invoke:WikiFunctions|arraymap|A@B@C@D|@|{X}|I like {X}|, }} → '''{{#invoke:WikiFunctions|arraymap|A@B@C@D|@|{X}|I like {X}|, }}'''
 
|Prints <code>formula</code> repeatedly with instances of <code>variable</code> replaced by members of <code>array</code>, separated by <code>separator</code> string. Note: Parameters cannot be output by the arraymap, though the {{tl|#invoke}} can be substituted to have the output value print to the wikitext with functioning parameters.
 
|-
 
|<code>lua</code>
 
|<code>args[]</code> (see desc)
 
|{{#invoke:tl|new|#invoke:WikiFunctions|lua|math|sqrt|4}} -> '''{{#invoke:WikiFunctions|lua|math|sqrt|4}}'''<br/>{{#invoke:tl|new|#invoke:WikiFunctions|lua|math|pi}} -> '''{{#invoke:WikiFunctions|lua|math|pi}}'''<br/>{{#invoke:tl|new|#invoke:WikiFunctions|lua|string|len|"lol"}} -> '''{{#invoke:WikiFunctions|lua|string|len|"lol"}}'''
 
|Prints Lua variable or function output. The parameters are names of tables, methods, and properties until the functions finds a value or function. If it reaches a value it prints it, if it reaches a function it uses the remaining passed parameters as parameters for that function.
 
|}
 
 
====paramargs====
 
<code>paramargs</code> is a function designed to be used in conjunction with templates. The goal of the function is to allow templates to use an infinite number of parameters without needing to be converted to Lua themselves. The general gist of the template is that the templates that use the function submit the parameters submitted to it (in pages it is transcluded in), and runs small string based functionality on them. Its features are similar in manner to [[#arraymap|<code>arraymap</code>]].
 
 
All of <code>paramargs</code> parameters are named. Though the template is designed to take the numbered parameters submitted by other templates, it can use numbered parameters in itself to do the same thing.
 
 
{|class="full-width table" style="text-align:left"
 
!Parameter
 
!Default
 
!Purpose
 
|-
 
|<code>first</code>
 
|1
 
|The number of the first auto-numbered parameter to include.
 
|-
 
|<code>omit</code>
 
|0
 
|The number of auto-numbered parameters at the end of the argument list to exclude.
 
|-
 
|<code>variable</code>
 
|"{X}"
 
|The variable representing an input's value in the format.
 
|-
 
|<code>length variable</code>
 
|false
 
|The variable representing the total number of values input.
 
|-
 
|<code>iteration variable</code>
 
|false
 
|The variable representing an input's iteration/number in list.
 
|-
 
|<code>format</code>
 
|variable
 
|The string returned, with instances of variables inside it changed to intended values on output.
 
|-
 
|<code>separator</code>
 
|""
 
|The content that appears between nodes.
 
|-
 
|<code>before</code>
 
|""
 
|The content that appears before if any parameters are submitted.
 
|-
 
|<code>after</code>
 
|""
 
|The content that appears after if any parameters are submitted.
 
|-
 
|<code>escape</code>
 
|false
 
|Boolean for whether to escape characters. Allowing escape characters allows text to be processed after parameters are input. Enables escaping of all code-corruptors.
 
|-
 
|<code>escape pipe</code>
 
|<code>\</code> (nil)
 
|String to replace with the pipe character (<code>{{#tag:nowiki|{{!}}}}</code>). If <code>escape</code> is false but <code>escape pipe</code> is specified, then escapes pipe but not necessarily others.
 
|-
 
|<code>escape tempin</code>
 
|<code>{@</code> (nil)
 
|String to replace with the template-in string (<code>{&#123;</code>). If <code>escape</code> is false but <code>escape tempin</code> is specified, then escapes template-in strings but not necessarily others.
 
|-
 
|<code>escape tempout</code>
 
|<code>@}</code> (nil)
 
|String to replace with the template-out string (<code>}}</code>). If <code>escape</code> is false but <code>escape tempout</code> is specified, then escapes template-out strings but not necessarily others.
 
|-
 
|<code>escape equals</code>
 
|<code>~</code> (nil)
 
|String to replace with the equals character (<code>=</code>). If <code>escape</code> is false but <code>escape equals</code> is specified, then escapes equals but not necessarily others.
 
|}
 
 
As examples:
 
 
:{{tl|#invoke:WikiFunctions|paramargs|A|B|C}} -> '''{{#invoke:WikiFunctions|paramargs|A|B|C}}'''
 
 
:{{tl|#invoke:WikiFunctions|paramargs|variable{{=}}@|iteration variable{{=}}#|format{{=}}#: |separator{{=}}"<br/>"|A|B|C}} -> '''{{#invoke:WikiFunctions|paramargs|variable=@|iteration variable=#|format=#: @|separator=, <nowiki/>|A|B|C}}'''
 
 
:{{tl|#invoke:WikiFunctions|paramargs|variable{{=}}_X|iteration variable{{=}}_#|length variable{{=}}_%|format{{=}}_X ([%\_#/_%] complete)|escape{{=}}true|escape tempin{{=}}[|escape tempout{{=}}]|A|B|C}} -> '''{{#invoke:WikiFunctions|paramargs|variable=_X|iteration variable=_#|length variable=_%|format=<li>_X ([%\_#/_%] complete)|escape=true|escape tempin=[|escape tempout=]|start=<ol>|end=</ol>|A|B|C}}'''
 
 
An example of a template that uses <code>paramargs</code> is {{tl|sideicon}}. A user can input infinite parameters of release codenames. The template's use of the function is:
 
 
{{tl|#invoke:WikiFunctions|paramargs|variable{{=}}{X}|format{{=}}<span id{{=}}"{X}-icon"></span>}}
 
 
An example of an input might be: {{tl|sideicon|FFI|FFII}}. Therefore the result on the page would be: {{tag|span|id=FFI-icon|<nowiki/>}}{{tag|span|id=FFII-icon|<nowiki/>}}.
 
 
====paramprops====
 
<code>paramprops</code> is a function designed to be used in conjunction with templates. The goal of the function is to allow the same code to be applied to a property of any name, and not have each valid property name be whitelisted. Templates that use the function submit the parameters submitted to it (in pages it is transcluded in), and runs small string based functionality on them. Its features are similar in manner to [[#arraymap|<code>arraymap</code>]].
 
 
The properties are not returned in the order they are input, it returns them in a seemingly random order.
 
 
All of <code>paramprops</code> parameters are named. Unlike <code>[[#paramargs|paramargs]]</code>, supplying parameters within the invoke rather than transclusions is less advised, though blacklisting of the used properties still allows it to function appropriately.
 
 
{|class="full-width table" style="text-align:left"
 
!Parameter
 
!Default
 
!Purpose
 
|-
 
|<code>omit</code>
 
|{}
 
|Lua table of blacklisted properties. Do note that as a Lua-syntax parameter the string inputs have to be surrounded by quotations.
 
|-
 
|<code>variable</code>
 
|"{v}"
 
|The variable representing an input's value in the format.
 
|-
 
|<code>property</code>
 
|"{k}"
 
|The variable representing the input's property name in the format.
 
|-
 
|<code>format</code>
 
|variable
 
|The string returned, with instances of variables inside it changed to intended values on output.
 
|-
 
|<code>separator</code>
 
|""
 
|The content that appears between nodes.
 
|-
 
|<code>before</code>
 
|""
 
|The content that appears before if any parameters are submitted.
 
|-
 
|<code>after</code>
 
|""
 
|The content that appears after if any parameters are submitted.
 
|-
 
|<code>escape</code>
 
|false
 
|Boolean for whether to escape characters. Allowing escape characters allows text to be processed after parameters are input. Enables escaping of all code-corruptors.
 
|-
 
|<code>escape pipe</code>
 
|<code>\</code> (nil)
 
|String to replace with the pipe character (<code>{{!}}</code>). If <code>escape</code> is false but <code>escape pipe</code> is specified, then escapes pipe but not necessarily others.
 
|-
 
|<code>escape tempin</code>
 
|<code>{@</code> (nil)
 
|String to replace with the template-in string (<code>{&#123;</code>). If <code>escape</code> is false but <code>escape tempin</code> is specified, then escapes template-in strings but not necessarily others.
 
|-
 
|<code>escape tempout</code>
 
|<code>@}</code> (nil)
 
|String to replace with the template-out string (<code>}}</code>). If <code>escape</code> is false but <code>escape tempout</code> is specified, then escapes template-out strings but not necessarily others.
 
|-
 
|<code>escape equals</code>
 
|<code>~</code> (nil)
 
|String to replace with the equals character (<code>=</code>). If <code>escape</code> is false but <code>escape equals</code> is specified, then escapes equals but not necessarily others.
 
|}
 
 
As examples:
 
 
:{{tl|#invoke:WikiFunctions|paramprops|A{{=}}1|B{{=}}2|C{{=}}3}} -> '''{{#invoke:WikiFunctions|paramprops|A=1|B=2|C=3}}'''
 
 
:{{tl|#invoke:WikiFunctions|paramprops|format{{=}}{k}: {v}|omit{{=}}{"omit", "format"}|A{{=}}1|B{{=}}2|C{{=}}3}} -> '''{{#invoke:WikiFunctions|paramprops|format={k}: {v}|omit={"omit", "format"}|A=1|B=2|C=3}}'''
 
 
:{{tl|#invoke:WikiFunctions|paramprops|variable{{=}}V|property{{=}}K|format{{=}}K {{=}} V|separator{{=}}, {{tag|nowiki|/}}|before{{=}}{ {{tag|nowiki|/}}|after{{=}}|{{tag|nowiki|/}} }|omit{{=}}{"variable", "property", "format", "separator", "before", "after"}|A{{=}}1|B{{=}}2|C{{=}}3}} -> '''{{#invoke:WikiFunctions|paramprops|variable=V|property=K|format=K = V|separator=, <nowiki/>|before={ <nowiki/>|after=|<nowiki/> }|omit={"variable", "property", "format", "separator", "before", "after"}|A=1|B=2|C=3}}'''
 
 
An example of a template that uses <code>paramprops</code> is {{tl|tag}}. A user can input any attribute by using the attribute name as the name of the parameter. The template's use of the function is:
 
 
{{#invoke:WikiFunctions|paramprops|format=}}
 
 
{{tl|#invoke:WikiFunctions|paramargs|variable{{=}}{X}|format{{=}}{{tag|nowiki/}} <span class="kw3">{k}</span><span class="sy0">{{=}}</span><span class="st0">"{v}"</span>}}
 
 
An example of an input might be: {{tl|tag|div|class{{=}}aclass|id{{=}}anid|data-lol{{=}}madeup|content}}. This would appear as: {{tag|span|class=aclass|id=anid|data-lol=madeup|content}}.
 
 
==Where to write==
 
Lua can only be process when inside a page in the Module namespace. This means it is not possible to test things in your own personal userspace. To test things [[Module:Sandsea]] should be utilized. The console in the edit form of a module page may also be a sufficient place to do testing without needing to save anything.
 
 
An easy way to write scripts with syntax highlighting support is to use [http://www.compileonline.com/execute_lua_online.php this website], however importing Modules stored on the wiki is impossible this way so they have to be partially copied over; and any tags used in printed outputs will not display because the tags will be interpreted as HTML.
 
 
Functions designed to be common use within scripts can be added to [[Module:FFWiki]]. Small functions designed to be invoked within templates can be added to [[Module:WikiFunctions]]. Collections of related functions are stored in individual modules, such as [[Module:StringFunctions]]. Collections of related functions are stored in individual modules, such as [[Module:Array]]. Larger and more complex functions or related groups of functions may also be stored at their own module, such as [[Module:Tl]] or [[Module:Codename]].
 
 
A single syntax error can prevent an entire module from working, and therefore any other scripts that reference functions in a module may also stop working. If one is unsure if what they are doing they should first test in a safe environment (Module:Sandsea, console, external Lua executor). The Module namespace is a a small controlled area, supervised by {{group|designer}}. All edits and additions to important modules and creation of new ones will be reviewed and evaluated.
 
 
==How to write==
 
===Comments===
 
Comments allow text to avoid being interpreted. These are used for programmer's notes. In-line comments are indicated by two dashes; all code on the line following this is not read as code. Starting a new line will end the comment, the only time a new line is seen as syntactical.
 
<source lang="lua" class="block">
 
a = b--comment
 
b = a
 
</source>
 
 
Block comments start the same way as an in-line comment, however following it to open square brackets (<code>[[</code>) should be used. The block comment closes when it sees two close square brackets (<code>]]</code>).
 
<source lang="lua" class="block">
 
a = b--[[ comment
 
b = a
 
a = b ]]
 
b = a
 
</source>
 
 
It is possible for two close square brackets to appear in valid syntax code. It is for this reason that it is advised block comments are not used to comment out sections of code.
 
 
===Statements===
 
<source lang="lua" class="block">
 
<member> = <value>
 
</source>
 
A standard statement Lua is a member name followed by an assign symbol (<code>=</code>, equals sign) followed by a value. A statement may also be the declaration of a variable (and the implicit assigning of <code>nil</code>), or the variable may be declared and assigned in the same statement.
 
 
As an example:
 
<source lang="lua" class="block">
 
variablename = 5
 
</source>
 
 
The running of a function is also a valid statement even if is not returning a value.
 
<source lang="lua" class="block">
 
functionname()
 
</source>
 
 
There is no syntax to separate statements, only the logical end of a statement indicates its end. For example, the assignment symbol, concatenation symbol, and other arithmetic and logical operators will always be followed by a value as part of the same statement. But if a member were to follow a member or value immediately then it would be seen as part of a new statement. Semi-colons can be placed after each statement, though they are not needed. New lines are typically used to follow statements for benefit of those reading or writing the script.
 
 
Structures in Lua do not have an implicit end. Keywords are used to indicate code is written for the different parts of the structure. Most structured end with the <code>end</code> keyword.
 
 
===Arithmetic===
 
Arithmetic allows processing of values.
 
 
{|class="half-width table" style="text-align:left"
 
!style="width:20%"|Operator
 
!Meaning
 
|-
 
|style="text-align:center;font-family:monospace"|+
 
|Addition
 
|-
 
|style="text-align:center;font-family:monospace"|-
 
|Subtraction.
 
|-
 
|style="text-align:center;font-family:monospace"|*
 
|Multiplication
 
|-
 
|style="text-align:center;font-family:monospace"|/
 
|Division.
 
|-
 
|style="text-align:center;font-family:monospace"|%
 
|Modulus.
 
|-
 
|style="text-align:center;font-family:monospace"|^
 
|Exponentiation.
 
|}
 
 
This means that on the value part of the equation there does not have to be a single static value, there could be a calculation.
 
 
As an example:
 
<source class="block" lang="lua">
 
variablename = 5 + 5
 
</source>
 
The member <code>variablename</code> now holds a numeric value of 10.
 
 
The [[#math|<code>math</code>]] library contains additional mathematical functions.
 
 
===Concatenation===
 
Concatenation is the process of connecting two strings. The operator for concatenation is <code>..</code> (two dots).
 
 
For example:
 
<source class="block" lang="lua">
 
variablename = "T" .. "he"
 
</source>
 
<code>variablename</code> holds the value "The".
 
 
===Logic===
 
Logical operators compare values and then return either <code>true</code> or <code>false</code>. Most structures that effect flow make use of logic. Logical operators asks the browser a question, and depending on the browser's answer the code will do different things.
 
 
Below are a list of built-in evaluators:
 
 
{|class="half-width table" style="text-align:left"
 
!style="width:20%"|Operator
 
!Meaning
 
|-
 
|style="text-align:center;font-family:monospace"|==
 
|Equal to.
 
|-
 
|style="text-align:center;font-family:monospace"|<
 
|Less than.
 
|-
 
|style="text-align:center;font-family:monospace"|<=
 
|Less than or equal to.
 
|-
 
|style="text-align:center;font-family:monospace"|>
 
|Greater than.
 
|-
 
|style="text-align:center;font-family:monospace"|>=
 
|Greater than or equal to.
 
|-
 
|style="text-align:center;font-family:monospace"|~=
 
|Not equal to.
 
|}
 
 
<source class="block" lang="lua">
 
5 == 4 --> false
 
5 == 5 --> true
 
5 == 6 --> false
 
5 < 4 --> false
 
5 < 5 --> false
 
5 < 6 --> true
 
5 <= 4 --> false
 
5 <= 5 --> true
 
5 <= 6 --> true
 
5 > 4 --> true
 
5 > 5 --> false
 
5 > 6 --> false
 
5 >= 4 --> true
 
5 >= 5 --> true
 
5 >= 6 --> false
 
5 ~= 4 --> true
 
5 ~= 5 --> false
 
5 ~= 6 --> true
 
</source>
 
 
There are three further logic operators. The <code>not</code> operator negates the result. A true result will become false, and a false true.
 
<source class="block" lang="lua">
 
not true --> false
 
not false --> true
 
not 5==5 --> false
 
not 4==5 --> false
 
not (4==5) --> true
 
</source>
 
 
Note above the use of brackets is required in that scenario, otherwise it would read as "<source lang="lua" class="inline">(not 4) == 5"</source>.
 
 
The <code>and</code> operator allows multiple logic equations to be processed, and only if they are all true will the end result be true.
 
<source class="block" lang="lua">
 
1 == 1 and 2 == 2 and 3 == 3 --> true
 
1 == 3 and 2 == 2 and 3 == 1 --> false
 
1 == 2 and 2 == 3 and 3 == 1 --> false
 
not (1 == 3) and 2 == 2 and not (3 == 1) --> true
 
</source>
 
 
The <code>or</code> operator allows multiple logical equations to be processed, and if any one of them is true the end result will be true.
 
<source class="block" lang="lua">
 
1 == 1 or 2 == 2 or 3 == 3 --> true
 
1 == 3 or 2 == 2 or 3 == 1 --> true
 
1 == 2 or 2 == 3 or 3 == 1 --> false
 
</source>
 
 
===Data types===
 
Lua has only six main data types. <code>number</code>, <code>string</code>, and <code>boolean</code> are the basic data types, functions are of the <code>function</code> type, the <code>nil</code> value has a <code>nil</code> type, and Lua has its array and object data types as one in the <code>table</code> data type.
 
 
Data types are implicit and syntax determines what type of value an input is.
 
 
The global [[#_G.type|<code>type</code>]] function detects the data type of its input and returns it as a string. This is useful in validating inputs and handling them differently.
 
 
Lua does not have standard support for classes, though constructing functions and [[#Metatables|metatables]] can be set to append methods and static properties to tables, and functions can be used to standardize properties to create what are effectively classes. Although objects of these classes would be tables, the [[#.__type|.__type]] metaproperty (or [[#__type|.__type]] metamethod if the value is a function) can be used to give the object a type. The [[#ffwiki.type|<code>type</code>]] function in the [[#Module:FFWiki|Module:FFWiki]] library considers this in its return value.
 
 
====<code>string</code>====
 
Strings are text values. When using strings the text is wrapped in either, double quotes (<code>"</code>) or single quotes (<code>'</code>), more often than not the former though when working on HTML the latter is usually used to avoid conflicts with double-quotes for attributes. The backslash character (<code>\</code>) can be used to escape characters within a string, and <code>\n</code> is the new line character.
 
 
Alternatively, two square brackets (<code>[[</code>, <code>]]</code>) can be used for a multi-line string where new lines in the code are new lines on the screen. This syntax can be used like the others, however everything inside is viewed literally. Therefore a use of a backslash will be viewed as a backslash character.
 
 
Strings can be concatenated to form new strings. Numbers can also be concatenated with each other and other strings to form new strings, however all other data types will return an error if concatenation is attempted.
 
 
A string value can have its length returned by using the <code>#</code> character before it.
 
 
Strings can be compared alphabetically via the ID of the characters with the less and greater than operators (<code><</code>, <code>></code>, <code><=</code>, <code>>=</code>).
 
 
The <code>tostring</code> global function converts both boolean values and nil values into the string equivalents of their key words, and converting <code>function</code> and <code>table</code> values will return the string <code>"table"</code>.
 
 
The <code>ifnotblank</code> function in [[#Module:FFWiki|Module:FFWiki]] returns <code>false</code> for <code>nil</code> values and empty strings.
 
 
The <code>tochartable</code> function in [[#Module:String|Module:String]] returns the string as an auto-indexed table to capture aspects of a string without resorting to substrings each time.
 
 
====<code>number</code>====
 
Numbers are valid decimal numbers up to 14 significant figures, greater values use that <code>e+</code> notation, and more decimals are not counted. Numbers can also be input using hexadecimal notation by prefixing it with <code>0x</code>.
 
 
Numbers can have arithmetic and comparison logic performed on them. Strings can have also have arithmetic and logic performed on them if they contain valid number text. For example, <source lang="lua">5 + "5" == 10</source>.
 
 
The global <code>tonumber</code> returns input <code>number</code> values as is and converts numerically valid <code>string</code> values to <code>number</code>, but returns <code>nil</code> in every other circumstance.
 
 
====<code>boolean</code>====
 
There are two boolean values represented by keywords <code>true</code> and <code>false</code>.
 
 
The keyword <code>not</code> prefixing a boolean value will give it its opposite meaning, so <code>not true == false</code>.
 
 
When boolean values can be used in logic equations inputting only the value, <code>false</code> values will be treated equivalent to <code>nil</code> values. All other potential values are treated as <code>true</code>.
 
 
====<code>nil</code>====
 
The <code>nil</code> type is a null or undefined type and essentially not a value. When a variable or property is not declared but used the value will be<code>nil</code>. When a variable is declared and but not assigned a value or when a function parameter has no value passed the name holds the value of <code>nil</code>, and functions that end without returning a value will return <code>nil</code>.
 
 
A <code>nil</code> value cannot be stored in a named parameter of a table, otherwise the key will just be removed. They can be stored in auto-indexed parameters however.
 
 
====<code>function</code>====
 
A member of the <code>function</code> type is a function, whether assigned to a variable or created as a named function. The syntax for a function is starting with the <code>function</code> keyword, and a function must also contain brackets containing parameters and an <code>end</code> keyword; like: <source lang="lua" class="inline">function() end</source>
 
 
An unnamed function can be executed by surrounding it in brackets and then placing brackets after it to input the function's parameters
 
 
Functions can sometimes be passed as parameters in cases like the <code>string</code> library's <code>sort</code>, or in the [[#Module:Array|Module:Array]] library's <code>foreach</code>.
 
 
====<code>table</code>====
 
A table is a member that contains more members. This can mean auto-indexed numbers like in an array, or named properties like in a standard object, or both. Unlike most other languages, indexes in Lua begin from 1 rather than 0. A member that contains a table does not truly contain a table, rather it contains a link to a table. In this I mean if one were to assign one table (say variable <code>a</code>) of a table to another member, (say variable <code>b</code>), unlike other data types the table contained by either member is the same. Adding, removing, or modifying the table under one variable name will also change it at the other. This capability is most commonly seen in functions, as when a table is passed as a parameter to a function, modifications made to that table are made to the table where it was called from. The same cannot be performed with other data types and a modified value will have to be returned.
 
 
The syntax for a table is contents wrapped in curly braces (<code>{</code> and <code>}</code>) while its members are separated by commas. If a member is named then its section starts with the name of the parameter followed by an equals sign. If the name is ''complex'' then it will have to be wrapped in square brackets (<code>[</code>, <code>]</code>). Square brackets can also be use to encase a stored value (such as a variable) to name the property based on a calculated value.
 
 
The term "complex" here means if the name contains more than just the usual alphanumeric characters accepted in variable names. This includes strings containing a space, a dash, or an equals symbol, and it also includes and other value (besides <code>nil</code>) one would be able to put in this space. Values of even the <code>table</code> and <code>function</code> types will work.
 
 
<source lang="lua" class="inline">pname = "n-3" a = { "A", "B", n = 1, ["n-2"] = 2, [pname] = 3 }</source> would appear like this:
 
<pre>
 
a = {
 
[1] = "A",
 
[2] = "B",
 
["n"] = 1,
 
["n-2"] = 2,
 
["n-3"] = 3
 
}
 
</pre>
 
 
To call a member of a table there are two notations that can be used. For named parameters the table name can be followed by a dot (<code>.</code>) and then the property name. If the property name is complex for one of the previously mentioned reasons (e.g. contains a "-") then they cannot be called in this way.
 
 
When calling a complex string property name, a non-string property name, or via a stored name, then square-brackets have to be used to get the value. The table name is followed by square brackets containing the value.
 
 
New values can be added to a member after its creation by assigning values using the above mentioned syntax, e.g. <source lang="lua" class="inline">a[3] = "C"</source>. The <code>table</code> library's <code>insert</code> value allows an auto-indexed value to be added to the table, or a value inserted at a specified index (pushing the other ones up).
 
 
Named property values can be removed from the table by assigning <code>nil</code> to them. The <code>table</code> library's <code>remove</code> function removes the last auto-indexed member of the table, or removes a value at a specified index (pushing the other ones down).
 
 
The [[#Module:Array|Module:Array]] library contains functions to manage an array of data. The <code>pop</code> function removes the last-indexed member, the <code>shift</code> function removes the first-indexed member, the <code>push</code> function adds a new auto-indexed value to the end of the table, and <code>unshift</code> inserts a new value to the first index of the table, pushing the others up. The <code>concat</code> function adds the auto-indexed contents of other table onto the end of an original.
 
 
The number of auto-indexed elements in a table can be returned by prefixing the table with a hash (<code>#</code>). Named properties are ignored.
 
 
Some tables have special properties and are referred to as readonly tables. They are tables whose values cannot be changed and their length cannot be gauged with the hash. The table holding the arguments sent from {{tl|#invoke}} commands, <code>frame.args</code>, is one of these types of table. The [[#Module:FFWiki|Module:FFWiki]] library's <code>reargs</code> function clones the table into a normal table.
 
 
===Variables===
 
Variables come in two kinds, global and local. The difference is the [[#Scope|scope]]. Global are accessible from anywhere in the program while local can only be used from where they are declared and in deeper scopes. A scope is defined by a block, so the contents of a page are a block, the contents of a function on that page are a nested block, and the contents of a selection structure in that function is another nested block. Variables local to the page are accessible from everywhere on that page while variables local to the selection structure are local only to that part of the selection structure (the IF, ELSEIF, and ELSE are each their own block). One would typically indicate a block with the indentations of new lines (two spaces per block), though for shorter structures such as those containing one statement, it is likely that the entire structure will be on one line. Therefore the only way to know is to find where the syntax indicates the block should start and end.
 
 
Local variables are set when <code>local</code> precedes the variable name on the first time it is used. While this variable is in scope, assigning a value to a variable of that name will change its value. Prefixing a use of a variable with <code>local</code> while the previous is in scope will create a new variable. If it is in a deeper scope then the first defined one will be unreachable while in that scope, while setting the variable at the same level will make the original variable unreachable.
 
 
A global variable's declaration is implicit. Assigning a value to a variable that exists in no local scopes will assign it to a global variable, and if the global variable does not exist then it will be created. Global variables can be reached at any time despite local variables existing with the same name, and this is done through the <code>_G</code> object. <code>_G</code> contains all global objects which are properties of it. <code>_G.variablename</code> will always refer to the global variable. Declaring new global variables while a local one in scope is therefore done by creating it as a new property of <code>_G</code>.
 
 
===Scope===
 
Variables and functions can be placed in different scopes. The basic concept is that when variables are set they can be accessed only in areas of the program that need them. Members accessible from everywhere are in the global scope, while those within a smaller scope are in a local scope. The local scope can refer to any number of different levels. For example:
 
 
<source lang="lua" class="block">
 
i = 1 --global scope
 
do
 
local i = 2 --local scope
 
do
 
local i = 3 --more local scope
 
do
 
local i = 4 --even more local scope
 
end
 
end
 
end
 
</source>
 
 
To demonstrate the power of levels:
 
 
<source lang="lua" class="block">
 
i = 1 --global scope
 
print(i) --prints 1
 
do
 
print(i) --prints 1
 
local i = 2 --local scope
 
print(i) --prints 2
 
do
 
print(i) --prints 2
 
local i = 3 --more local scope
 
print(i) --prints 3
 
do
 
print(i) --prints 3
 
local i = 4 --even more local scope
 
print(i) --prints 4
 
end
 
print(i) --prints 3
 
end
 
print(i) --prints 2
 
end
 
print(i) --prints 1
 
</source>
 
 
As demonstrated above, there are four different <code>i</code> variables in play. The global <code>i</code>, the <code>i</code> local to the first <code>do</code>, and then the other two <code>i</code> variables inside their respective nested <code>do</code> structures.
 
 
Prefixing a value with <code>local</code> defines a variable and places it in the current scope. To get or set its value thereafter, <code>local</code> does not have to be prefixed. In fact, doing so at a deeper scope will only create a new variable at that deeper scope, making the variable at a higher level inaccessible during that scope.
 
 
If a local variable does not exist in a scope with the used name, then setting a value to a variable will create a global variable. This is seen above on the first line where <code>i</code> is created as a global variable. Although in the code sample prefixing it with <code>local</code> will produce the same output, they are not the same. There are two key differences:
 
 
#A local variable in a page is not accessible outside of that page.
 
#A global variable is always accessible.
 
 
By the second point we mean that if the first <code>i</code> was local, in deeper scopes once a local variable with the name of <code>i</code> were created we could not refer to the <code>i</code> in the highest scope. Members of the global scope are stored in the <code>_G</code> table. As a demonstration:
 
 
<source lang="lua" class="block">
 
i = 1
 
local j = 1
 
do
 
local i = 2
 
print(i) -- returns 2
 
print(_G.i) -- returns 1
 
local j = 2
 
print(i) -- returns 1
 
print(_G.j) -- returns nil
 
end
 
</source>
 
 
If local variables are obscured by local variables at a deeper level they become inaccessible inside that scope.
 
 
A deeper scope is created inside most structures. So there are separate scopes within a <code>function</code>, within an <code>if</code>, an <code>elseif</code>, and an <code>else</code>, within each <code>do</code> iteration (so each loop is its own scope).
 
 
So the below code sample is incorrect:
 
<source lang="lua" class="block">
 
if true then
 
local i = 1
 
else
 
local i = 2
 
end
 
return i
 
</source>
 
<code>nil</code> will be returned because neither declaration of <code>i</code> is in the same scope as the return.
 
 
This would instead be done like:
 
<source lang="lua" class="block">
 
local i
 
if true then
 
i = 1
 
else
 
i = 2
 
end
 
return i
 
</source>
 
 
Which would return <code>1</code>. However, in many of the cases as above, if the only purpose of the IF is to set different values to a variable then the Ternary IF, or inline IF, is simpler. The equivalent to the above is:
 
 
<source lang="lua" class="block">
 
local i = true and 1 or 2
 
return i
 
</source>
 
 
Or more simply the variable can be bypassed and <source lang="lua" class="inline">return true and 1 or 2</source> would work suitably.
 
 
As a further note to scope, when a Module is called via <code>require</code>, anything that happens inside that module occurs independently of where it was called from. This means any modifications to global variables do not apply to where it was called from. The value returned by the module is returned at the place it was called from, but nothing else of the environment is affected.
 
 
===Multiple Values===
 
Lua has a concept that allows more than one value to be the value in a statement. This does not refer to a table, but instead literally multiple values. The values are comma-separated. This is somewhat akin to a function's parameter inputs. As an example:
 
 
<source lang="lua" class="block">
 
local x = 5, 6
 
</source>
 
In the above example, x is being assigned a value of <code>5</code>, the <code>6</code> gets discarded. But not only does Lua allow multiple values to be assigned, but also multiple members to be assigned to:
 
 
<source lang="lua" class="block">
 
local x, y = 5
 
</source>
 
In the above example, <code>x</code> is <code>5</code>, and <code>y</code> is <code>nil</code>. Naturally, a more logical use of this would be like so:
 
<source lang="lua" class="block">
 
local x, y = 5, 6
 
</source>
 
Where both values are assigned numbers, <code>x</code> gets <code>5</code> and <code>y</code> gets <code>6</code>. This could be done for an infinite number of values.
 
 
More than just assigning multiple values to variables in the statement however, multiple values have places elsewhere. For example, some functions return multiple values. One example is the <code>string</code> library's <code>[[#string.gsub|gsub]]</code> function. The function returns the string with replacements made, but as a second value it returns the number of replacements made.
 
 
<source lang="lua" class="block">
 
string.gsub("aba", "a", "c") --> returns "cbc", 2
 
</source>
 
 
The benefit of this is allowing the return of more details about the process without to return all the data in a table.
 
 
Earlier it was mentioned that this multiple value technique was akin to function parameters, and this is actually applicable. Take for example the global [[#print|<code>print</code>]] function. The function can take infinite parameters, and putting the result of a function that returns multiple values in there prints all those values.
 
 
<source lang="lua" class="block">
 
print(string.gsub("ababa", "a", "c")) --> prints "cbcbc 3"
 
print(string.gsub("ababa", "a", "c") .. "") --> prints "cbcbc"
 
</source>
 
In the second example only the first value is returned because processing occurs and therefore it only happens to the first value while the others are ignored and discarded.
 
 
Multiple values can often be unwieldy, especially when there will be an unpredictable amount. The [[#Module:Table|Module:Table]] library's [[#table.pack|<code>pack</code>]] function can be used to compact all of these, regardless of amount, into a table. Conversely, the same library's [[#table.unpack|<code>unpack</code>]] function converts a table's values into a multiple value list which may be useful for passing as a function's parameters.
 
 
If one were to want to store a later value but not earlier ones, a function could be used to grab the specific values, or an assignment could be made and immediately overwritten. For example:
 
 
<source lang="lua" class="block">
 
--Overwritten assignment (assign first value to a, assign second value to a)
 
local a, a = string.gsub("aba", "a", "c") --> a = 2
 
--Anonymous function in Lua 5.1 / FFWiki
 
local a = (function(...) return arg[2] end)(string.gsub("aba", "a", "c")) --> a = 2
 
--Anonymous function in Lua 5.2+
 
local a = (function(...) arg = table.pack(...) return arg[2] end)(string.gsub("aba", "a", "c")) --> a = 2
 
</source>
 
 
===Structures===
 
====DO====
 
In its basic use, the DO structure sections off a block a code. This has implications on [[#Scope|scope]]. The main use of <code>do</code> is within [[#Iteration|iteration structures]] where the block can be executed numerous times.
 
 
The syntax for the structure starts with the <code>do</code> keyword and ends with the <code>end</code> keyword.
 
 
:<source lang="lua" class="inline">do</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">end</source>
 
 
Demonstrating a DO structure:
 
<source lang="lua" class="block">
 
do
 
local i = 5
 
print(i) --prints 5
 
end
 
print(i) --prints nil
 
</source>
 
 
====Selection====
 
=====IF, ELSE, and ELSEIF=====
 
The IF structures test a condition for a value other than <code>false</code> or <code>nil</code>. If it is not one of those then the code inside the IF will be executed.
 
 
The syntax for the structure starts with the <code>if</code> keyword which is followed by the condition value, then the <code>then</code> keyword, followed by a block of code, and ends with the <code>end</code> keyword.
 
 
:<source lang="lua" class="inline">if </source> <code>''value''</code> <source lang="lua" class="inline"> then</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">end</source>
 
 
Demonstrating IF:
 
<source lang="lua" class="block">
 
if true then
 
print("true")
 
end
 
if false then
 
print("false")
 
end
 
</source>
 
The result of the above would be <code>true</code> would be printed. Since the condition for the second IF structure is <code>false</code> it never runs.
 
 
As part of the IF structure, an ELSE structure can be included. Before the <code>end</code> keyword can be the <code>else</code> keyword, which can be followed by a block of code to execute instead if the condition is <code>false</code> or <code>nil</code>
 
 
:<source lang="lua" class="inline">if </source> <code>''value''</code> <source lang="lua" class="inline"> then</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">else</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">end</source>
 
 
Demonstrating ELSE:
 
<source lang="lua" class="block">
 
if true then
 
print("true")
 
else
 
print("not true")
 
end
 
if false then
 
print("false")
 
else
 
print("not false")
 
end
 
</source>
 
The result of the above would be the printing of <code>true</code> and <code>not false</code>. The condition is true on the first so runs the IF block, and false on the second so runs the ELSE block.
 
 
Multiple ELSEIF structures can also be included. These follow the IF within IF structures and offer alternate conditions to run if the first is false. These use the <code>elseif</code> and <code>then</code> keywords.
 
 
:<source lang="lua" class="inline">if </source> <code>''value''</code> <source lang="lua" class="inline"> then</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">elseif </source> <code>''value''</code> <source lang="lua" class="inline"> then</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">else</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">end</source>
 
 
Demonstrating ELSEIF:
 
<source lang="lua" class="block">
 
if x==nil then
 
print("Non-existent")
 
elseif x<0 then
 
print("Negative")
 
elseif x==0 then
 
print("Zero")
 
else
 
print("Positive")
 
end
 
</source>
 
The result of the above would be the printing of <code>non-existent</code> if <code>x</code> does not exist, <code>Negative</code> if <code>x</code> is a number less than 0, <code>Zero</code> if <code>x</code> is 0, and <code>Positive</code> in all other circumstances.
 
 
=====Ternary IF=====
 
Ternary IF, also known as inline IF, is a way of checking a condition and returning an output. Its benefit over using a standard IF structure is that it works inline. This avoids repeating of variable names and such things and can be done in a single statement. The <code>and</code> and <Code>or</code> keyword are used to fulfill this.
 
 
It comes in two forms. The first tests a value is not <code>false</code> or <code>nil</code>, and prints it if not, else it prints another given value.
 
 
:<code>''value''</code> <source lang="lua" class="inline"> or </source> <code>''else''</code> <source lang="lua" class="inline"> then</source>
 
 
For example:
 
<source lang="lua" class="block">
 
print("me and" .. (x or "who knows"))
 
</source>
 
The above prints "<code>me and who knows</code>" if <code>x</code> is <code>nil</code> or <code>false</code> or "<code>me and </code>" the value of <code>x</code> if it is. For example, if <code>x</code> is {{USERNAME|you}}, then the display will be "<code>me and {{USERNAME|you}}</code>".
 
 
The second form tests a value and prints another given value if true, a given value if not <code>false</code> or <code>nil</code>, or another given value in other circumstances.
 
 
:<code>''test''</code> <source lang="lua" class="inline"> and </source> <code>''true'' </code> <source lang="lua" class="inline"> or </source> <code>''false'' </code>
 
 
For example:
 
<source lang="lua" class="block">
 
print(x .. "? " .. (x==5 and (x .. " is my favorite number") or ("I hate " .. x)))
 
</source>
 
The above prints "<code>5? 5 is my favorite number</code>" if <code>x</code> is <code>5</code>; or "<code><value of x>? I hate <value of x></code>" if the value is anything else.
 
 
As an example of the benefits of ternary IF, the above with regular IF would be written like so:
 
<source lang="lua" class="block">
 
local y = x .. "? "
 
if x==5 then
 
y = y .. x .. "my favorite number"
 
else
 
y = y .. "I hate " .. x
 
end
 
print(y)
 
</source>
 
A variable has to be used to achieve the same thing, and specified multiple times. A variable could be avoided, but then <code>print</code> would have to be specified both times, as would the string (<code?x .. "? "</code>).
 
 
It should be noted that if a <code>false</code> or <code>nil</code> value is the output for <code>true</code> in the second version of ternary IF, it will not function as one might expect. The way to solve this should be as simple as reversing the condition (such as wrapping it in a <code>not</code>) and reversing the outputs.
 
 
For example:
 
<source lang="lua" class="block">
 
print(ab=="" and nil or ab) --always prints value of ab
 
 
print(not (ab=="") and ab or nil) --prints nil if ab=="", prints ab otherwise
 
 
print(ab~="" and ab or nil) --same as above using dedicated operator
 
</source>
 
 
If the goal of the logic test is to output boolean values based on an input value (and not necessarily boolean), a ternary IF does not need to be used. What one might hope is achieved (but is not) by (<code>''test'' and false or true</code>) can be achieved by simply using <code>not logic</code>. An equivalent to (<code>''test'' and false or true</code>) is then <code>not not logic</code>.
 
 
As a demonstration:
 
<source lang="lua" class="block">
 
local a = "a"
 
local b = not not a --> b = true
 
local c = not not d --> c = false
 
</source>
 
 
====Iteration====
 
Iteration refers to loops. Loops use test values to decide whether to execute block of code, then re-runs the test to decide whether to execute it again. The test usually uses a variable that can change during the course of the block of code, or that the structure itself manages. If this did not occur and the test was not <code>nil</code> or <code>false</code>, then the block would loop indefinitely, unless there were a <code>break</code> or <code>return</code> inside the structure.
 
 
<code>break</code> exits out of the immediate loop (the innermost loop, but it will not exit out of a loop the innermost loop is nested in).
 
 
The <code>return</code> statement also exits out of loops, but it also exits out of the entire function. See [[#Functions|Functions]] for details.
 
 
So a basic loop:
 
<source lang="lua" class="block">
 
i = 0
 
while true do
 
if i == 5 then break end
 
i = i + 1
 
print(i)
 
end
 
</source>
 
The above loop has an always <code>true</code> condition, so it will loop forever unless the content decides otherwise. The first statement inside the DO block tests if <code>i</code> is equal to 5. At this point it is 0, so it will continue. Then it adds 1 to the value of <code>i</code> and prints the value, <code>1</code>. It then returns to the loop's condition, <code>true</code>, so continues from the start. The loop will print "1", "2", "3", "4", and "5", then on the next loop i==5 will be true and <code>break</code> will be reached, exiting the loop and continuing the code.
 
 
Other languages have a <code>continue</code> statement, Lua does not.
 
 
=====WHILE=====
 
A WHILE loop continues to loop while a condition is true. The syntax is <code>while</code> followed by the value, <code>do</code> followed by the code, followed by <code>end</code>.
 
 
:<source lang="lua" class="inline">while </source> <code>''value''</code> <source lang="lua" class="inline"> do</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">end</source>
 
 
Lua's [[#FOR|FOR]] loop does work in the typical fashion, so one application may be to test if a value, incremented in the code, is less than a value.
 
 
<source lang="lua" class="block">
 
local object = { "A", "B", true, "C", "D" }
 
local i = 1
 
while i <= #object do
 
if object[i] == true then i = i + 1 else print(object[i]) end
 
i = i + 1
 
end
 
</source>
 
The above will print "A", "B", and "D". The third iteration will detect true which increments <code>i</code> by 1 (on top of the standard increment), so "C" is skipped over.
 
 
=====REPEAT UNTIL=====
 
The REPEAT UNTIL loop has two differences to the [[#WHILE|WHILE]] loop. The first is that the loop repeats until the condition is true (so while the condition is false), rather than while the condition is true. The other different is that it is a post-check loop. What this means is the condition is tested only after the block of code has been executed once.
 
 
:<source lang="lua" class="inline">repeat</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">until </source> <code>''value''</code>
 
 
To show how this works:
 
<source lang="lua" class="block">
 
i = 5
 
while i < 5 do
 
print(i)
 
end
 
--nothing printed
 
repeat
 
print(i)
 
until not(i < 5)
 
--prints 5 once because the condition is only tested at the end
 
</source>
 
 
=====incremental FOR=====
 
The incremental FOR creates a variable specifically for the loop (which is inaccessible outside of it) and increases it by an amount until it is greater than or equal to another specified value. The increment does not have to be specified and will otherwise be 1. The values are separated by commas, and looks like this:
 
 
With increment automatically defined as 1:
 
:<source lang="lua" class="inline">for </source> <code>''variable''</code> <source lang="lua" class="inline"> = </source> <code>''value''</code> <source lang="lua" class="inline">, </source> <code>''until''</code> <source lang="lua" class="inline"> do</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">end</source>
 
 
With increment specified:
 
:<source lang="lua" class="inline">for </source> <code>''variable''</code> <source lang="lua" class="inline"> = </source> <code>''value''</code> <source lang="lua" class="inline">, </source> <code>''until''</code> <source lang="lua" class="inline">, </source> <code>''increment''</code> <source lang="lua" class="inline"> do</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">end</source>
 
 
The maximum and increment values remain the same throughout. So if using a variable for conditions, these values are only evaluated at the start. Furthermore, while the variable created at the start can be modified in the loop, when it gets back to the top it will be the value it was at the beginning of the iteration plus the increment defined at the start.
 
 
A typical use for an incremental FOR loop would be this:
 
 
<source lang="lua" class="block">
 
local object = { "A", "B", "C", "D" }
 
for i = 1, #object do
 
print(object[i])
 
end
 
</source>
 
This would print "A", "B", "C", and "D". A benefit of using incremental FOR over [[#WHILE|WHILE]] is that the variable is automatically disposed of when the loop finishes, while a benefit of WHILE is more control over the incrementing variable. A key difference between them is how variables and functions may be used in the conditions of a WHILE since they are evaluated on each loop, while functions and variables used in an incremental FOR are evaluated once.
 
 
[[#FOR IN|FOR IN]] can iterative over <code>ipairs</code> which works in a similar way when iterating over tables, but incremental FOR offers more control over increment amount and starting value. Incremental FOR is faster. One may opt for <code>ipairs</code> when modifying a table at the same time however. FOR IN with <code>ipairs</code> also breaks the loop when a <code>nil</code> value is found, which is not the case for incremental FOR.
 
 
=====FOR IN=====
 
A FOR IN loop loops through a set of items. The most common way to use it is to use <code>pairs</code> or <code>ipairs</code> whose value would be a table. The loop then iterates over the table's members (only auto-indexed ones until <code>nil</code> in the latter) and each iteration has a given block run on it. Two variables can be set, one that stores the current key name (or property name), and one that store's the current value.
 
 
Syntax with pairs:
 
:<source lang="lua" class="inline">for </source> <code>''keyvariable''</code> <source lang="lua" class="inline">, </source> <code>''valuevariable''</code> <source lang="lua" class="inline"> in pairs(</source> <code>''table''</code> <source lang="lua" class="inline">) do</source>
 
::<code>''code''</code>
 
:<source lang="lua" class="inline">end</source>
 
 
The value variable (and its preceding comma) are not needed if the value's do not need to be used.
 
 
Examples:
 
<source lang="lua" class="block">
 
local object = { "A", "B", "C", "D", n = 4 }
 
for k, v in pairs(object) do
 
print(k .. ": " .. v)
 
end
 
</source>
 
The printed output would be:
 
<pre>
 
1: A
 
2: B
 
3: C
 
4: D
 
n: 4
 
</pre>
 
 
<source lang="lua" class="block">
 
local object = { "A", "B", "C", "D", n = 4 }
 
for k, v in ipairs(object) do
 
print(k .. ": " .. v)
 
end
 
</source>
 
The printed output would be:
 
<pre>
 
1: A
 
2: B
 
3: C
 
4: D
 
</pre>
 
 
====Functions====
 
Functions are samples of code but they are not used where they are written (most of the time). Instead they are called from one or more other points in the code (most of the time). Functions take parameters, which are values passed to the function when calling it.
 
 
Functions can modify accessible variables and modify passed tables, though their most common use is with returning values. The <code>return</code> keyword can be used in a function's code and it will terminate processing of the function and return the following value to where the function was called from. <code>return</code> does not have to be followed by a value, and if it does not <code>nil</code> will be returned. Multiple values can be returned, and to make use of them two variables can be set to assign the function value.
 
 
<source lang="lua" class="block">
 
function twoplustwo()
 
return 2+2
 
end
 
print(twoplustwo()) --> 4
 
</source>
 
 
A function's parameters are listed linearly in brackets following the function name. When defining the function parameter names can be written comma-separated. The names of these parameters can be used in the function's body, and the values passed to the function when called use these names. The order they are entered into the function is the same as the order the parameters on the function. A special parameter name, <code>...</code>, can be used as the last parameter of the function. What this means for the function is an infinite number of arguments. In the version of Lua the wiki uses, <code>...</code> can be used as an auto-indexed table of values, so looping through them and specifying specific values by following it with square brackets works.
 
 
When calling a function and only a single string value is passed, brackets do not need to be used and instead the value placed after it will be seen as its single parameter. This is not true for any other circumstance. Due to the fact that brackets are usually needed, and required in other languages, including brackets is general practice. The single exception to this rule is when using <code>[[#_G.require|require]]</code>, where typically brackets are foregone.
 
 
Not all parameters need to have a value passed to them, a value of <code>nil</code> will be assigned to those that are not used in a call. If parameters are optional the function will usually contain code that assigns a default value or switches logic.
 
 
<source lang="lua" class="block">
 
function plus(numA, numB)
 
return numA + numB
 
end
 
print(plus(2, 4)) --> 6
 
</source>
 
 
Functions are usually named and use the following syntax:
 
<source lang="lua" class="block">
 
function functionname(comma, separated, parameters)
 
code
 
end
 
functionname("parameters", "a")
 
</source>
 
 
Functions can be used anonymously though, which means they can be passed as a type of data or executed immediately. An example of a where an anonymous function is useful is the [[Module:Array]] library's [[#array.foreach|foreach]] function, where a function is run on each auto-indexed member of a table. An anonymous function uses the same syntax but a function name is not specified.
 
 
An anonymous function can be executed without assigning it to a variable by wrapping it in brackets, then following it with brackets and the input parameters.
 
 
An anonymous function would look like this:
 
<source lang="lua" class="block">
 
(function(a) return 2+a end)(3) --> 5
 
</source>
 
 
One of the reasons one may do this is to create a deeper scope, though in Lua this can be done using the [[#DO|DO]] structure. However one of the more logical reasons is that it allows a block of code to be written and whatever is returned assigned to a variable. The difference is like with [[#Ternary IF|Ternary IF]], the structure returns a value and does not need to do the assigning itself.
 
 
<source lang="lua" class="block">
 
--with anonymous function
 
local d = (function()
 
if 1 == 2 then
 
return 5
 
end
 
return 3
 
end)()
 
 
--with REPEAT (for break, repeat's post-check and "until true" guarantees one iteration)
 
local d
 
repeat
 
if 1 == 2 then
 
d = 5
 
break
 
end
 
d = 3
 
until true
 
 
--standard
 
local d
 
if 1 == 2 then
 
d = 5
 
else
 
d = 3
 
end
 
</source>
 
 
===Methods===
 
Methods are functions, though they are functions executed in a certain way. Functions can be a property of a table, or they can be assigned via metatables (see [[#Classes|Classes]] for additional information about that), and if they are either of these things then they can be executed like a method.
 
 
A method execution is like a function execution, but instead of a dot, a colon is used. So for example:
 
<source lang="lua" class="block">
 
a.()--standard function execution
 
a:()--method execution
 
</source>
 
 
The thing that separates them though is that in a method execution the first parameter is always the calling variable itself. This is the only reason the execution of a function from an instance is needed, rather than executing the function from a library. Below are three calls doing identical things:
 
 
<source lang="lua" class="block">
 
local a = "ABC"
 
string.lower(a) --function execution from library
 
a.lower(a) --function execution from instance
 
a:lower() --method execution from instance
 
--All of the above return "abc"
 
</source>
 
 
From above you can see how the middle function is worthless as it is a shorter version of the function execution from library, and the initial specification of <code>a</code> is meaningless. It is ultimately just confusing and should be avoided. The method execution does the same thing, and in a clear and more logical way.
 
 
If you are carrying what you know of methods over from other languages, it is not possible to run executions on literal values. The value must can be stored in a variable or property, but you can also still run the methods by wrapping the string in brackets.
 
 
As an example of setting up a single-use method:
 
<source lang="lua" class="block">
 
local tbl = { "a", "b", "c", initfunc = function(self) return self[1] end}
 
function tbl.postfunc(self)
 
return self[1]
 
end
 
function tbl:postmeth()
 
return tbl[3]
 
end
 
--the table is called "tbl"
 
--tbl[1] is "a"
 
--tbl[2] is "b"
 
--tbl[3] is "c"
 
--tbl.initfunc is a function that returns the first parameter of a submitted table
 
--tbl.postfunc is a function that returns the second parameter of a submitted table
 
--tbl:postmeth is a function that returns the third parameter of a submitted table
 
 
print(tbl:initfunc())--prints "a"
 
print(tbl:postfunc())--prints "b"
 
print(tbl:postmeth())--prints "c"
 
</source>
 
 
The above shows a method being declared, <code>function tbl:postmeth()</code>: there is no reason to do this. The first parameter does not get declared so there is no way to reference it so in the end it gets no benefit of being a method. Defining a function as a method still allows it to function as a regular function. In the example <code>print(tbl.postmeth())</code> also prints "c".
 
 
===Metatables===
 
A table becomes a metatable when it is assigned as one to another table. Metatables can contain a number of specific parameters such as <code>__index</code> which contain functions that get executed when certain events take place. These are referred to as ''metamethods''.
 
 
One of the most common uses for metatables is to use default parameters, so this will be explained first. Although it was said that functions are assigned to the parameters, <code>__index</code> is one of a few exception as it also allows for a table to be assigned. Properties where values are assigned rather than an executing function are called ''metaproperties''. Assigning a table to <code>__index</code> makes the assigned table's properties available to tables using the metatable as their metatable.
 
 
The main function here is [[#_G.setmetatable|<code>setmetatable</code>]].
 
 
<source lang="lua" class="block">
 
local mt = {} --create metatable
 
mt.__index = { a = "A", b = "B", sequel = function(self, prop) return self[prop] .. " II" end } --set properties to inherit
 
local newtable = { b = "1" } --the table we want to assign the metatable to
 
 
setmetatable(newtable, mt)
 
 
print(newtable.a) --prints "A" from metatable
 
print(newtable.b) --prints "1" from self
 
print(newtable:sequel("a")) --prints "A II" from metatable func, A from metatable
 
print(newtable:sequel("b")) --prints "1 II" from metatable func, B from self
 
</source>
 
 
So in the above, a metatable is created, and that metatable has indexes in its <code>__index</code> property. The metatable is assigned to a new table, and therefore when the program looks for properties in the table that do not exist, they defer to the metatable's <code>__index</code>.
 
 
That is the basic and standard use for metatables, but they get more advanced than that. Functions are typically set to the properties that run when on certain conditions. When <code>__index</code> has a function it is run the script whenever an index is searched for but not found.
 
 
So this below example uses it to throw errors rather than <code>nil</code>, which could be totally annoying in many circumstances when you just rather just have <code>nil</code> returned.
 
<source lang="lua" class="block">
 
local mt = {}
 
mt.__index = function(t, k)
 
if type(k) == "number" then
 
if k == 0 then error("Indexes start at 1 in Lua dood.")
 
elseif k < 0 then error("A negative number? Are you sure that's what you're looking for? Nothing here.")
 
else error((k-#t) .. " out of range. The last index is at " .. #t .. ".")
 
end
 
else error("No value at this property.")
 
end
 
end
 
 
local array = {"A"}
 
 
setmetatable(array, mt)
 
</source>
 
 
The above is fairly self-explanatory. The parameter order is the table being used, the key being looked for. So if <code>array[42]</code> was looked for, the error would be "41 out of range. The last index is at 1.". <code>array[1]</code> would return "A" because the script isn't run if the searched field exists.
 
 
A more standard example may be what <code>array</code> from [[Module:Array]] uses. When [[#array.new|<code>array.new</code>]] is used, a metatable is assigned to a table that allows array methods to be used more easily. It uses this code:
 
<source lang="lua" class="block">
 
array.__index = function(t, k) if k=="new" or k=="isarray" then return nil end return array[k] end
 
</source>
 
 
What this does is fairly easy to explain, if ":new" and ":isarray" were tried to be used then <code>nil</code> would be returned, in all other circumstances it will look look for the index in the array table.
 
 
One thing to note is that <code>__index</code> is ignored when setting a metatable. Ergo, though with the current example every object using the array metatable will have it returned in their <code>.__index</code> property, setting the case of an array as a metatable will not work. The property has to specifically belong to the object.
 
 
Copying the metatable from another element is possible though, the [[#_G.getmetatable|<code>getmetatable</code>]] function returns the given metatable of the given object.
 
 
Below is a table of the usable events. Do note, the parameter names can be named anything and it is only the order that matters. In uses parameter names are often shortened to a single letter for convenience.
 
 
====Metaproperties====
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Property
 
!Description
 
|-
 
|class="code"|{{A|.__index|__index}}
 
|Table of properties used when not found in table. Can also contain a function and be used as [[#__type|a metamethod]].
 
|-
 
|class="code"|{{A|.__metatable|__metatable}}
 
|Value returned when <code>getmetatable</code> is called on table.
 
|-
 
|class="code"|{{A|.__type|__type}}
 
|Value returned when [[#ffwiki.type|<code>ffwiki.type</code>]] is called on table. Can also contain a function and be used as [[#__type|a metamethod]].
 
|}
 
 
 
====Metamethods====
 
Called so because the functions automatically pass themselves. Values are always functions.
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Property
 
!style="width:20%"|Parameters
 
!Description
 
|-
 
|class="code"|{{A|__index}}
 
|<code>table</code><br/><code>key</code>
 
|Called when an index not in the table is requested. Returns function return as value. <code>rawget</code> runs get ignoring <code>__index</code>.
 
|-
 
|class="code"|{{A|__newindex}}
 
|<code>table</code><br/><code>key</code><br/><code>value</code>
 
|Called when a previously undefined value is assigned. Not called for <code>table.insert</code>. Assignment does not take place. To otherwise set a previously undefined value, <code>rawset</code> must be used.
 
|-
 
|class="code"|{{A|__call}}
 
|<code>table</code><br/><code>args[]</code>
 
|Function that runs when the table is used as a function.
 
|-
 
|class="code"|{{A|__tostring}}
 
|<code>table</code>
 
|Returns function value when [[#_G.tostring|<code>tostring</code>]] is used on table.
 
|-
 
|class="code"|{{A|__len}}
 
|<code>table</code>
 
|Returns function value when the <code>#</code> (hash) operator is used on table. Will not work in most cases in 5.1
 
|-
 
|class="code"|{{A|__type}}
 
|<code>table</code>
 
|Returns function value when [[#ffwiki.type|<code>ffwiki.type</code>]] is used on table.
 
|-
 
|class="code"|__unm
 
|<code>table</code>
 
|Returns function value when attempting to use table as a negative (e.g. -table).
 
|-
 
|class="code"|__add
 
|<code>a</code> - First value<br/><code>b</code> - Second value
 
|Runs when table is being added to another value and returns function return value. If both tables have metatables with <code>__add</code> metamethod, then leftmost table's is used.
 
|-
 
|class="code"|__sub
 
|<code>a</code> - Subtracted from<br/><code>b</code> - Subtraction value
 
|Runs when table is being subtracted from another value, or when value is being subtracted from table, and returns function return value. If both tables have metatables with <code>__sub</code> metamethod, then subtracted from's table is used.
 
|-
 
|class="code"|__mul
 
|<code>a</code> - First value<br/><code>b</code> - Second value
 
|Runs when table is being multiplied with another value and returns function return value. If both tables have metatables with <code>__mul</code> metamethod, then leftmost table's is used.
 
|-
 
|class="code"|__div
 
|<code>a</code> - Divided value<br/><code>b</code> - Divided into
 
|Runs when table is being divided into another value, or value is being divided into table, and returns function return value. If both tables have metatables with <code>__div</code> metamethod, then divided value's is used.
 
|-
 
|class="code"|__mod
 
|<code>a</code> - Divided value<br/><code>b</code> - Divided into
 
|Runs when table is being modulusified with another value. If both tables have metatables with <code>__mod</code> metamethod, then divided value's is used.
 
|-
 
|class="code"|__pow
 
|<code>a</code> - Multiplied value<br/><code>b</code> - Power value
 
|Runs when table is being raised to power of another value, or value is being raised to power of the table, and returns function return value. If both tables have metatables with <code>__pow</code> metamethod, then multiplied value's is used.
 
|-
 
|class="code"|__concat
 
|<code>a</code> - First value<br/><code>b</code> - Second value
 
|Runs when table is being concatenated with to another value and returns function return value. If both tables have metatables with <code>__add</code> metamethod, then leftmost table's is used.
 
|-
 
|class="code"|__add
 
|<code>a</code> - First value<br/><code>b</code> - Second value
 
|Runs when table is being added to another value and returns function return value. If both tables have metatables with <code>__add</code> metamethod, then leftmost table's is used.
 
|-
 
|class="code"|__eq
 
|<code>a</code> - First table<br/><code>b</code> - Second table
 
|Runs when tables are being evaluated for equality (<code>==</code>), are not the same table, and share the same metamethod. If these conditions are met then the function return value is used as the logic value. Also run with same conditions with <code>~=</code>, and opposite value returned instead.
 
|-
 
|class="code"|__lt
 
|<code>a</code> - First table<br/><code>b</code> - Second table
 
|Runs when tables are being evaluated with less-than operator <code><</code>. The function return value is used as the logic value. If both tables have metatables with <code>__lt</code> metamethod, then leftmost table's is used. Also run with same conditions with greater-than operator (<code>></code>), with parameters reversed.
 
|-
 
|class="code"|__le
 
|<code>a</code> - First table<br/><code>b</code> - Second table
 
|Runs when tables are being evaluated with less-than-or-equal-to operator <code><=</code>. The function return value is used as the logic value. If both tables have metatables with <code>__le</code> metamethod, then leftmost table's is used. Also run with same conditions with greater-than-or-equal-to operator (<code>>=</code>), with parameters reversed.
 
|}
 
 
===Importing modules===
 
Modules, or libraries, can be imported using the global [[#_G.require|<code>require</code>]] function. The parameter contains a string of the name of the module (always in the Module namespace) including the namespace. Modules define an object at the start, append properties (typically functions) and then return them at the end. The imported module is then returned to a variable.
 
 
<source lang="lua" class="block">
 
local modulename = require "Module:ModuleName" --format
 
local ffwiki = require "Module:FFWiki" --example
 
</source>
 
 
Importing of the more general libraries such as [[#Module:FFWiki|Module:FFWiki]] is typically done at the top of a module. Modules may also sometimes be defined in functions so the library is not always imported when the module may not even make reference to it. While the time to load a module is typically negligible, most of the time a call to a module results in the use of a single function so not much is usually lost in examples where it has to call a module twice when it could have done it once in an encompassing scope.
 
 
Some modules are designed to override existing ones with further functionality. This is true for [[#Module:String|Module:String]] and [[#Module:Array|Module:Array]]. In these instances defining variables of the name locally is not needed.
 
 
===Writing #invoke functions===
 
The {{tl|#invoke}} function takes two parameters, followed by an optional amount of other parameters, which can be named or otherwise. The first parameter matches the name of a module page, and the second matches the name of a function in that module page. The remaining parameters are packed into a Lua readonly table and submitted to the function. The function's returned value is printed to the page where it was found.
 
 
Functions using invoke must have its first (and usually only unless it is designed to be called in other ways aside from {{tl|#invoke}}) parameter titled <code>frame</code>. This parameter is a type, and the most important thing about it is it has a property called <code>args</code>, and this property will contain the aforementioned readonly table of parameters.
 
 
Therefore to use a parameter, one can type <code>frame.args[''parameter name'']</code> to get the value that was passed. The parameter names match those used in {{tl|#invoke}}, and unnamed parameters will be in sequence starting from <code>1</code> onwards. This functions identically to tables, where the value before the <code>equals</code> is the parameter name, and the contents after is the variable. All values passed as parameters are viewed as strings.
 
 
The readonly state of the table means two things, the first is that none of the values can be edited. Therefore if the programmer simply wants to use the input arguments to be put directly to use and have defaults then a new table will have to be created. The second is that the length of the table cannot be gathered. So a [[#FOR IN|FOR IN]] table cannot iterate over it unless one were to find out the value in another way. To fix this the <code>reargs</code> function on the [[#Module:FFWiki|Module:FFWiki]] library clones the readonly table into a normal table so arguments are reusable.
 
 
In templates blank values are often equivalent to undefined values. Wikitext does not have data types in the normal sense, so it is the closest to a nil type available. An unspecified variable, one the {{tl|#invoke}} never references, does count as <code>nil</code> though. Therefore to test whether parameters exist most of the time the value will have to be checked for not being <code>nil</code> or a blank string. Rather than doing this each time, the <code>ifnotblank</code> function in the Module:FFWiki library exists to check these two things and return <code>true</code> if the value is neither of the aforementioned values, or <code>false</code> if it is. If empty strings should be valid for the parameters, then a technique may be to make the blank value "@nil" instead, and have Lua convert that input to <code>nil</code>. Its status as a string that would unlikely be intended to be an actual input makes this simple.
 
 
Rather than using the <code>ifnotblank</code> function each time a parameter is used works, though rather than doing this for all parameters it may be easier to just convert all of the table's empty strings to <code>nil</code>. Of course, this cannot be done with the initial readonly arguments table, however the <code>emptystring</code> function in the Module:FFWiki library does the same thing as <code>reargs</code> but removes all parameters with empty strings from the table. This includes auto-numbered parameters, causing gaps in the numbers.
 
 
Though all parameter inputs are viewed as string by Lua, the <code>luaparam</code> function in the Module:FFWiki library evaluates a table containing string values into the different data types. This means a parameter surrounded by quotation marks will be seen as a string, while "true", "false", and "nil" will be seen as those respective values, values inside of curly braces as tables, values surrounded by quotation marks as strings, or calculations as numeric. Functions are detected but they cannot be passed. Concatenation of strings work but is ultimately pointless. Reference to variables or functions also does not work. The detection of a table works by viewing if table syntax appears in the field (outside of a string). This is needed as when tables are used as the last parameter the end invoke syntax will confuse itself with it. Any characters placed before or after the table syntax are entirely ignored, so simply adding whitespace after the table syntax will resolve the issue.
 
 
The Frame object has a method called <code>getParent</code>. This method will call a new frame object, this frame object containing the parameters of the page that called the page containing the current frame. In simple, terms, if the page with the {{tl|#invoke}} is transcluded, then the parameters submitted to the page with the {{#tl|invoke}} will be stored in the parent frame. This means that creating a template containing nothing but an {{tl|#invoke}}, the name of a module, and the name of the function could be used identically to using an {{tl|#invoke}}, sans the need of stating the module and function name, so long as the script gets is args from <code>frame:getParent().args</code>. An easy way to use parameters from a template if used, but the {{tl|#invoke}} otherwise, is to use a statement that checks for parameters in the template. Like so:
 
<source lang="lua" class="block">
 
local f = frame:getParent().args[1] and frame:getParent() or frame
 
</source>
 
 
The reason storing the frame is suggested here is because it has other uses, though if one intends only to use the <code>args</code> parameter then that could be stored in the variable to make things simpler. The <code>1</code> for the parameter value can be changed to a mandatory named parameter if no non-named parameters are used.
 
 
Wikitext used as a parameter in an {{tl|#invoke}} is processed before it gets to the function. This means that parameters with defaults will always pass their defaults to the function and the parameter will be lost. Furthermore, parameters, templates, and MediaWiki tags will not be processed if returned from a Lua function. For templates the <code>expandTemplate</code> of a Frame object can be used. The function contains a table whose <code>title</code> parameter is the name of a template, and whose <code>args</code> parameter is a Lua table with the names of the arguments. For parameters, MediaWiki tags, and templates written in wikitext, the <code>preprocess</code> function of the Frame object can be used to process it. In this process, wikitext parameters are replaced with values from the Frame object's <code>args</code> property.
 
 
Though as stated, parameters with defaults will only have the defaults reach the Lua function. To avoid this the [[#Module:FFWiki#unescapewikitext|<code>unescapewikitext</code>]] function in the Module:FFWiki library can be used. Escaped syntax passed to the function can be passed to the script fine, then the script can convert it to the valid wikitext and have it go through the Frame object's <code>preprocess</code> method to do the conversion as desired. The escape strings replace existing ones, for example a backslash (<code>\</code>) instead of a pipe. If an escape string will conflict with other code then they can be re-specified through the function's parameters.
 
 
A lot of wiki functions will revolve around returning wikitext to the form, and most structures will be written using HTML tags. Therefore the [[#mw.html|mw.html]] library's Html object will need to be used. [[#HTML building|HTML building]] is explained in its own section.
 
 
===HTML Building===
 
Wikitext-valid HTML can be written and returned to the form just fine, however HTML can be better written programmatically. The [[#Html|Html]] class has a number of functions that modify parts of a HTML element separately, and can then return the HTML when the text is needed. Components of the element are stored in a table and is therefore much easier to manage than cutting and editing a string, or creating numerous temporary variables to help manage it.
 
 
A new Html object is created through the <code>mw.html.create</code> function. This has two parameters, the first is the string tag name, e.g. "div", and the second is an optional parameter boolean that can make the tag self-closing (if it isn't on the list of ones to do that automatically, like {{tag|br|/}} and {{tag|hr|/}})).
 
 
The new object can now have methods added. It is likely that the object will want to be stored in a variable, although on smaller projects this might not be needed. The methods can be added in the same statement as the object is created, or in a new statement from the variable, either is fine. So to demonstrate:
 
 
<source lang="lua" class="block">
 
local el = mw.html.create("div"):method() --method on creation
 
el:method() --method post-creation
 
</source>
 
 
To add or edit an attribute the [[#Html:attr|<code>attr</code>]] method can be used. Supplying the name and value in the first and second parameter works, or multiple attributes can be defined at the same time by inputting a table where the attribute names are the property names and the values are the table values. Not all attributes should be added in this way, <code>class</code> and <code>style</code> are exceptions since they do not contain a single value, however since classes and styles cannot be removed they can be reset through <code>attr</code> by specifying the attribute and inputting a blank string.
 
 
To add a class the [[#Html:addClass|<code>addClass</code>]] method can be used. The single parameter is a string, and multiple classes can be added by space-separating them in the string.
 
 
To add CSS to the style parameter two methods can be used. When adding new CSS specified in Lua the preferred method is to use the [[#Html:css|<code>css</code>]] method. The method works like <code>attr</code> in that one can be added by specifying name and value as parameters, or multiple can be added with a table.
 
 
The other method of adding CSS is the [[#Html:cssText|<code>cssText</code>]] method. This allows styles to be written out in plaintext, e.g. <code>color:red;font-weight:bold</code>. The reason why this is not preferred when specifying in Lua is that the property names are not checked to see if they already exist in the element. However, this method would need to be used if the CSS styles are specified in the parameters passed to the script.
 
 
Content inside of the tags can be added through a number of methods, and the order they are added in. For plain HTML text the [[#Html:wikitext|<code>wikitext</code>]] method is used. The input is literally just standard wikitext, although <code>\n</code> counts as a new line character. The [[#Html:newline|<code>newline</code>]] method is another way to add new lines and takes no parameters.
 
 
The [[#Html:node|<code>node</code>]] method adds a created HTML element inside the one being operated on. This could be one stored in a variable, or it could be created on the spot inside the method's brackets. The benefits of using a variable is that the element can still be modified after it is added by referencing the variable name. Sorting out the structure of the elements before handling their attributes is an acceptable way to manage things.
 
 
Alternatively to using <code>mw.html.create</code> inside of the <code>node</code> method, the [[#Html:tag|<code>tag</code>]] method can be used. Neither way is right or wrong although it offers a new option. The <code>tag</code> method takes he same properties as the <code>mw.html.create</code> method. The difference between <code>tag</code> and <code>node</code> is that the <code>node</code> method returns the object being operated on, while the <code>tag</code> method returns the newly created object. This means that following methods will apply to the newly created tag. Therefore when done editing the newly created tag, the [[#Html:done|<code>done</code>]] method can be used to return power to the element that created the tag. This method could be used a number of times to nest more and more tags, and therefore to return control to the originally created element, the <code>allDone</code> property can be used.
 
 
If assigning a value to a variable in the same string of methods as new tags are being used, returning control to the original element needs to be done at the end to store the outermost element. Intending to use an element as a string after creating a tag but not returning control will also not be targeting printing the outermost element.
 
 
An element can be recorded in the console with <code>print</code> or <code>mw.log</code>, and can be returned to a page by putting it as a return. If one were to want to use the tags as strings directly, such as with concatenation, then the element must be placed inside the global [[#_G.tostring|<code>tostring</code>]] function.
 
 
So here is an example. The Lua:
 
<source lang="lua" class="block">
 
local el = mw.html.create("div"):addClass("contentbox"):attr("id", "htmlbuildexample")
 
local header = mw.html.create("div"):addClass("header"):wikitext("Header")
 
el:node(header)
 
local content = "This is content"
 
el:wikitext(content):tag("div"):wikitext("[[File:Core-ffix.png|75px]]"):css("float", "right"):done():tag("div"):css({clear = "both", ["border-bottom"] = "1px solid black"}):allDone()
 
</source>
 
 
The wikitext:
 
<source lang="html5" class="block">
 
<div class="contentbox" id="htmlbuildexample"><div class="header">Header</div>This is content<div style="float:right;">[[File:Core-ffix.png|75px]]</div><div style="clear:both;border-bottom:1px solid black;"></div></div>
 
</source>
 
 
The display:
 
<div class="contentbox" id="htmlbuildexample"><div class="header">Header</div>This is content<div style="float:right;">[[File:Core-ffix.png|75px]]</div><div style="clear:both;border-bottom:1px solid black;"></div></div>
 
 
===Classes===
 
An object-orientated programming concept is classes. Classes are definitions for objects. Instances of the class inherit properties and methods from the class itself. Lua does not have classes, however using [[#Metatables|metatables]] we can utilize a form of inheritance.
 
 
A class defines a type of object, so an example of a class might be "Account" for a bank account. The "Account" class may have properties like "balance" and methods like "withdraw". An instance of the "Account" class would be a single account.
 
 
While I state that classes may have properties, this is not technically true. Properties can be added though they would have to be the same for all of the objects. Adding variable properties is not possible in this way, the properties would have to be added in the initializer.
 
 
A benefit of using classes is the methods are not attached to objects, they only hold a reference to their class which stores the methods. This means additional functions are not added to the table.
 
 
Technically speaking properties cannot be set into the class. The property and the value belong to the class object, so trying to modify that property will just be adding the property to the current object and make the class's property inaccessible. There are multiple ways that properties could be handled. The class could contain a table of all the available properties. This could be cycled through in the constructor, and have the values added at that point. The table in the constructor could be made useful and contain default values for when <code>nil</code> values are presented, but if a default value were to be <code>nil</code> then it just would not appear in the table. In the end it may just be simpler to define the properties in the constructor.
 
 
So here's how one might do it:
 
 
<source lang="lua" class="block">
 
-----------
 
-- class --
 
-----------
 
Account = {
 
withdraw = function(self, value) self.balance = self.balance - value return self.balance end,
 
deposit = function(self, value) self.balance = self.balance + value return self.balance end
 
}
 
 
--------------------------------------------------------
 
-- set Account's methods to be looked up if not found --
 
--------------------------------------------------------
 
Account.__index = Account
 
 
-----------------
 
-- constructor --
 
-----------------
 
function Account.new(balance)
 
--set up new object
 
obj = {}
 
--inherit class methods
 
setmetatable(obj, Account)
 
--set new property
 
obj.balance = balance or 0
 
--return new object
 
return obj
 
end
 
 
---------------------------------
 
-- creating object from class --
 
---------------------------------
 
local a = Account.new(6)
 
</source>
 
 
The object <code>a</code> above contains the property <code>balance</code> which holds a value of <code>6</code> and that is all. However the link set up with the Account class allows it to use the methods found on the Account object. If one were to try to use methods on it:
 
 
*<source lang="lua" class="inline">a.balance</source> -> '''6'''
 
*<source lang="lua" class="inline">a:deposit(1)</source> -> '''7'''
 
*<source lang="lua" class="inline">a.balance</source> -> '''7'''
 
*<source lang="lua" class="inline">a:withdraw(3)</source> -> '''4'''
 
 
The first sample shows the input balance registered, the second shows <code>:deposit</code> operating on the number depositing 1 currency (adding 1 to existing), and the third one shows the balance updated. The fourth sample shows that <code>:withdraw</code> works too.
 
 
===Console===
 
When editing a page in the Module namespace a console will appear below the editform. Running the console executes the contents of the editform (only the first time) followed by the contents of the console. If a submission is valid, modifications made to the environment including the addition of variable (be them local or global), or alterations made to existing elements are retained. Line numbers in the console start from line 5, and every valid line submitted increments the line number. In other words, submit a valid statement in the console and that will be line 5. Submit the same statement again and that will be line 6.
 
 
When the console is cleared or the editform's contents are changed, the next time the console is submitted the environment is reset and the editform is re-submitted.
 
 
Instances of <code>mw.log()</code> in the editform will print their values to the console output. Instances of <code>mw.log()</code> and <code>print()</code> in the console will print their values to the console output. <code>print()</code> in the editform will cause an error to be thrown. If an error is thrown then no values will be printed to the editform even if the error occurs after them, which means that detecting the point of error can be difficult.
 
 
Any global variables set in the editform cannot be reached by the console. This includes values imported from other modules. To make use of these in the console they can be imported in the console submission. However, modules that return an object can still have their methods and properties used in the console and are stored in the <code>p</code> object. For example, if the Module contains the text: <code>ModName = {} ModName.v = 5 return ModName</code>, then submitting the console containing <code>print(p.v)</code> will print <code>5</code> in the console output.
 
 
If functions are designed to be called with {{tl|#invoke}} then they will use the <code>frame</code> argument. Therefore to be able to debug the function within the console one would have to do do something like <source lang="lua" class="inline">frame = {} frame.args = { "File:ElfToad-ffv-ios.png", "Elf Toad" } print(p.generate(frame))</source>, where the contents of <source lang="lua" class="inline">frame.args</source> are the inputs split into array members where pipes would be used on the page, and the method name after <code>p</code> would be the name of the function being tested. It should be noted that there is a slight difference in doing this because <source lang="lua" class="inline">frame.args</source> when discovered through {{tl|#invoke}} is a readonly table, this means that ascertaining its length and changing its values is impossible, the same is not true for a standard table. Methods belonging to the frame object will also not carry over.
 
 
Furthermore, the value printed in the console will be plain wikitext. To see the output value one would have to copy it into a normal page's editform and preview. This is not exactly the same because wikitext syntax for templates does not evaluate when returned from Lua, but would when text is copied from an edit form. If the value returned from the console goes off screen, placing the cursor left of the text and clicking down and dragging down a bit should highlight the entire line without highlighting anything else.
 
 
If there is text in the console then pressing the Enter key will run the contents of the console. Holding shift when pressing the Enter key will create a new line. Pressing down on the lowermost line will make the console's contents blank, while pressing up on the top line will show the previously submitted console code (or the code typed before pressing Down if returning from blanking by that method). Ctrl+Z and Ctrl+Y allows undoing and redoing to go back to the last or following minor change.
 
 
==Libraries==
 
===''global''===
 
Globally stored functions and variables are stored in <code>_G</code>, though they can be used without needing a prefix. However, if one were to call a global function or variable by a string, then they will need to use <code>_G</code> to reference it. For example, <code>_G["print"]()</code>.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|_G.ipairs|ipairs}}
 
|<code>table</code>
 
|for k, v in ipairs({"A", B= "C"}) do print(k .. v) end -> '''0A'''
 
|Assigns key and value pairs to variables and iterates over auto-indexed of tables when used in a <code>for</code> loop.
 
|-
 
|class="code"|{{A|_G.pairs|pairs}}
 
|<code>table</code>
 
|for k, v in pairs({"A", B= "C"}) do print(k .. v) end -> '''0A''', '''BC'''
 
|Assigns key and value pairs to variables and iterates over all members of table when used in a <code>for</code> loop.
 
|-
 
|class="code"|{{A|_G.print|print}}
 
|<code>value</code>
 
| -
 
|Prints value to console. Causes script errors when used in modules, <code>[[#mw.log|mw.log]]</code> should be used instead.
 
|-
 
|class="code"|{{A|_G.require|require}}
 
|<code>module</code>
 
|require "Module:FFWiki"
 
|Executes a module without the module being able to modify the environment, such as globals.
 
|-
 
|class="code"|{{A|_G.tonumber|tonumber}}
 
|<code>object</code>
 
|tonumber("4") -> {{#invoke:WikiFunctions|lua|tonumber|4}}
 
|Returns number of converted value, otherwise nil if it fails to convert.
 
|-
 
|class="code"|{{A|_G.tostring|tostring}}
 
|<code>object</code>
 
|tostring(4) -> "{{#invoke:WikiFunctions|lua|tostring|4}}"<br/>tostring(true) -> '''"{{#invoke:WikiFunctions|lua|tostring|true}}"'''
 
|Returns string of converted value. Most objects are converted to string automatically when concatenated or printed.
 
|-
 
|class="code"|{{A|_G.type|type}}
 
|<code>object</code>
 
|type(5) -> '''{{#invoke:WikiFunctions|lua|type|5}}'''<br/>type("5") -> '''{{#invoke:WikiFunctions|lua|type|"5"}}'''<br/>type(true) -> '''{{#invoke:WikiFunctions|lua|type|true}}'''<br/>type({}) -> '''{{#invoke:WikiFunctions|lua|type|{} }}'''<br/>type(function() end) -> '''{{#invoke:WikiFunctions|lua|type|function() end}}'''<br/>type(nil) -> '''nil'''<br/>type(2, "3") -> '''{{#invoke:WikiFunctions|lua|type|2|"3"}}'''
 
|Returns string name of type of object.
 
|-
 
|class="code"|{{A|_G.error|error}}
 
|<code>string</code>
 
| -
 
|Throws an error with reason specified.
 
|-
 
|class="code"|{{A|_G.pcall|pcall}}
 
|<code>function</code>
 
|pcall(function() end) -> '''{{#invoke:WikiFunctions|lua|pcall|function() end}}'''<br/>pcall(function() a = "a" + "a" end) -> '''false''', '''Lua error at line 1: attempt to perform arithmetic on a string value'''
 
|Runs function and returns Boolean for whether it was valid (<code>false</code> if causes error). Found errors do not terminate script, though are returned as second output.
 
|-
 
|class="code"|{{A|_G.setmetatable|setmetatable}}
 
|<code>table</code> - Assigned to.<br/><code>metatable</code>
 
| -
 
|Assigns [[#Metatables|metatable]] to given table. Returns table.
 
|-
 
|class="code"|{{A|_G.getmetatable|getmetatable}}
 
|<code>table</code>
 
| -
 
|Returns table metatable of given table. If metatable has [[#.__metatable|.__metatable]] property then that is returned, or if [[#__metatable|__metatable]] is a function then the function is run as method and value is returned.
 
|-
 
|class="code"|{{A|_G.rawset|rawset}}
 
|<code>table</code><br/><code>index</code><br/><code>value</code>
 
|a = {} _G.rawset(a, "b", "c") -> {{#invoke:WikiFunctions|lua|rawset|{}|a|"b"|"c"}}
 
|Assigns value to index of table. Avoids [[#__newindex|__newindex]] metamethod. Returns table.
 
|-
 
|class="code"|{{A|_G.rawget|rawget}}
 
|<code>table</code><br/><code>index</code>
 
|a = {} _G.rawget(a, "b") -> '''{{#invoke:WikiFunctions|lua|rawget|{}|a|"b"}}'''
 
|Returns index of table. Avoids deferring to [[#.__index|__index]] or running the metamethod of [[#.__index|__index]].
 
|}
 
 
===string===
 
A number of <code>string</code> functions return multiple parameters. Because <code>print</code> can take infinite parameters, when a string function is returned and printed multiple values are printed. Though if one were to use the return as a value then only the first returned value would be used.
 
 
So for example, <code>print(string.byte("ABC", 1, 3))</code> prints "<code>65 66 67</code>", while <code>print(string.byte("ABC", 1, 3) .. "")</code> prints "<code>65</code>".
 
 
Strings must be stored in variables or properties to use the methods.
 
 
[[#Module:String|Module:String]] can be imported over this module to add additional functions.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|string.byte|.byte}}<br/>{{A|String:byte|:byte}}
 
|<code>string</code><br/><code>start</code> - Index of first character (default: 1)<br/><code>end</code> - Index of last character (default: <code>start</code>)
 
|string.byte("ABC") → '''{{#invoke:WikiFunctions|lua|string|byte|"ABC"}}'''<br/>string.byte("ABC", 2) → '''{{#invoke:WikiFunctions|lua|string|byte|"ABC"|2}}'''<br/>string.byte("ABC", 2, 3) → '''66''', '''67'''
 
|Returns byte indices of character between <code>start</code> and <code>end</code> as multiple values.
 
|-
 
|class="code"|{{A|string.char|.char}}
 
|<code>args[]</code> - Byte value of characters
 
|string.char(65, 66, 67) → '''{{#invoke:WikiFunctions|lua|string|char|65|66|67}}'''
 
|Returns string of byte indexes converted to characters.
 
|-
 
|class="code"|{{A|string.find|.find}}<br/>{{A|String:find|:find}}
 
|<code>string</code><br/><code>search</code> - Substring to find within <code>string</code><code>offset</code> - Index to start searching from, negative values count back from end (default: 1).<br/><code>plain</code> - Boolean for plaintext searching, (default: false).
 
|string.find("bac", "ac") → '''2''', '''3'''<br/>string.find("cac", "c", 2) → '''3''', '''3'''<br/>string.find("cac", "c", -1) → '''3''', '''3'''<br/>string.find("cac", "b") → '''nil'''
 
|Returns first and last index <code>substring</code> found within <code>string</code> after <code>offset</code> index as multiple values. Uses [http://lua-users.org/wiki/PatternsTutorial Lua Patterns] unless <code>plain</code> is true.
 
|-
 
|class="code"|{{A|string.gsub|.gsub}}<br/>{{A|String:gsub|:gsub}}
 
|<code>string</code><br/><code>search</code> - string being replaced.<br/><code>replace</code> - string replacing.<br/><code>replacements</code> - Number of replacements (optional).
 
|string.gsub("hahaha", "a", "e") → '''hehehe''', '''3'''<br/>string.gsub("hahaha", "a", "e", 2) → '''heheha''', '''2'''
 
|Returns string with instances of <code>search</code> substring replaced by <code>replace</code> substring and replacements made as multiple values. If <code>replacements</code> is used, makes specified replacements from start of string. Uses [http://lua-users.org/wiki/PatternsTutorial Lua Patterns].
 
|-
 
|class="code"|{{A|string.len|.len}}<br/>{{A|String:len|:len}}
 
|<code>string</code>
 
|string.len("ABC") → '''{{#invoke:WikiFunctions|lua|string|len|"ABC"}}'''
 
|Returns length of string. <code>#[string]</code> works in the same way.
 
|-
 
|class="code"|{{A|string.lower|.lower}}<br/>{{A|String:lower|:lower}}
 
|<code>string</code>
 
|string.lower("AbC") → '''{{#invoke:WikiFunctions|lua|string|lower|"AbC"}}'''
 
|Returns string in lowercase.
 
|-
 
|class="code"|{{A|string.rep|.rep}}<br/>{{A|String:rep|:rep}}
 
|<code>string</code><br/><code>times</code> - Number of times to repeat.
 
|string.rep("ha", 3) → '''{{#invoke:WikiFunctions|lua|string|rep|"ha"|3}}'''
 
|Returns string repeated specified times.
 
|-
 
|class="code"|{{A|string.reverse|.reverse}}<br/>{{A|String:reverse|:reverse}}
 
|<code>string</code>
 
|string.reverse("nametag") → '''{{#invoke:WikiFunctions|lua|string|reverse|"nametag"}}'''
 
|Returns string with character order reversed.
 
|-
 
|class="code"|{{A|string.sub|.sub}}<br/>{{A|String:sub|:sub}}
 
|<code>string</code><br/><code>start</code> - First index<br/><code>end</code> - Last index (default: <code>#string</code>)
 
|string.sub("heathen", 4) → '''{{#invoke:WikiFunctions|lua|string|sub|"heathen"|4}}'''<br/>string.sub("heathen", -3) → '''{{#invoke:WikiFunctions|lua|string|sub|"heathen"|-3}}'''<br/>string.sub("heathen", 2, 4) → '''{{#invoke:WikiFunctions|lua|string|sub|"heathen"|2|4}}'''<br/>string.sub("heathen", 4, -2) → '''{{#invoke:WikiFunctions|lua|string|sub|"heathen"|4|-2}}'''
 
|Returns string reading from character at <code>start</code> index to <code>end</code> index. If values are negative, counts back from end of string.
 
|-
 
|class="code"|{{A|string.upper|.upper}}<br/>{{A|String:upper|:upper}}
 
|<code>string</code>
 
|string.upper("aBc") → '''{{#invoke:WikiFunctions|lua|string|upper|"aBc"}}'''
 
|Returns string in uppercase.
 
|}
 
 
===table===
 
Past versions of Lua had the <code>getN</code> function which returned the greatest numeric index of a table, or in an auto-indexed table, the length. This can be done using <code>#[table]</code>.
 
 
None of these are methods.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|table.insert|.insert}}
 
|(<code>table</code>, <code>value</code> or (<code>table</code>, <code>index</code>, <code>value</code>)<br/><code>table</code><br/><code>index</code> - Index to insert at (default: <code>#table</code>)<br/><code>value</code> - Value to insert
 
|table.insert({"A", "B"}, "C") → (table: {"A", "B", "C"})<br/>table.insert({"A", "B"}, 2, "C") → (table: {"A", "C", "B"})
 
|Inserts value at given index in table. <code>index</code> must be a number, but can be any number. Moves existing and following indexes up. No return, so input table should be pre-stored.
 
|-
 
|class="code"|{{A|table.remove|.remove}}
 
|<code>table</code><br/><code>index</code> - Index to remove at (default: <code>#table</code>)
 
|table.remove({"A", "B", "C"}) → '''{{#invoke:WikiFunctions|lua|table|remove|{"A", "B", "C"} }}''' (table: {"A", "B"})<br/>table.remove({"A", "B", "C"}, 2) → '''{{#invoke:WikiFunctions|lua|table|remove|{"A", "B", "C"}|2}}''' (table: {"A", "C"})
 
|Removes value at given index in table. <code>index</code> must be a number, but can be any number. Moves following indexes down. Returns removed value.
 
|-
 
|class="code"|{{A|table.concat|.concat}}
 
|<code>table</code><br/><code>delimiter</code> (default: empty string)<br/><code>start - From index (default: 1)</code><br/><code>end</code> - To index (default: <code>#table</code>)
 
|table.concat({"A", "B", "C"}) → '''ABC'''<br/>table.concat({"A", "B", "C"}, "@") → '''A@B@C'''<br/>table.concat({"A", "B", "C"}, "", 2) → '''BC'''<br/>table.concat({"A", "B", "C"}, "", 1, 2) → '''AB'''
 
|Returns string of table member values from start index to end index separated by delimiter.
 
|-
 
|class="code"|{{A|table.sort|.sort}}
 
|<code>table</code><br/><code>function</code> - Comparative function (default: <code>function(i, j) if i < j then return true end end</code>)
 
|table.sort({"B", "A", "D", "C"}) → (table: {"A", "B", "C", "D"})<br/>table.sort({"B", "A", "D", "C"}, function(i, j) if i > j then return true end end) → (table: {"D", "C", "B", "A"})
 
|Reorders table elements using function. The function needs to take two parameters and return true. No return is equivalent to return false, or "do not switch". The default function orders smallest or alphabetically.
 
|}
 
 
===math===
 
<code>mod</code> works but has been removed in 5.2. To use the function a <code>%</code> can be used in an equation, for example what was <code>math.mod(5, 2)</code> can be expressed as <code>5%2</code>. The <code>fmod</code> function works similarly, however it rounds towards 0 so negative numbers are treated like inverse positive numbers (e.g. <code>-5%4</code> is <code>3</code> and <code>math.fmod(-5, 4)</code> is -1, and 5%-4 is <code>-3</code> and math.fmod(5, -4) is <code>1</code>).
 
 
The property <code>huge</code> contains the value <code>inf</code>.
 
 
The property <code>pi</code> contains the value <code>3.1415926535898</code>.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|math.sqrt|.sqrt}}
 
|<code>number</code>
 
|math.sqrt(4) -> '''{{#invoke:WikiFunctions|lua|math|sqrt|4}}'''
 
|Returns square root of <code>number</code>. Equivalent to <code>number^1/2</code>
 
|-
 
|class="code"|{{A|math.pow|.pow}}
 
|<code>number</code><br/><code>power</code>
 
|math.pow(5, 2) -> '''{{#invoke:WikiFunctions|lua|math|pow|5|2}}'''
 
|Returns square root of <code>number</code>. Equivalent to <code>number^power</code>.
 
|-
 
|class="code"|{{A|math.fmod|.fmod}}
 
|<code>number</code><br/><code>mod</code>
 
|<code>math.fmod(5, 4)</code> -> {{#invoke:WikiFunctions|lua|math|fmod|5|4}}<br/><code>math.fmod(-5, -4)</code> -> {{#invoke:WikiFunctions|lua|math|fmod|-5|-4}}<br/><code>math.fmod(-5, 4)</code> -> {{#invoke:WikiFunctions|lua|math|fmod|-5|4}}<br/><code>math.fmod(5, -4)</code> -> {{#invoke:WikiFunctions|lua|math|fmod|5|-4}}
 
|Returns <code>number</code> modulo <code>mod</code> rounded towards 0.
 
|-
 
|class="code"|{{A|math.min|.min}}
 
|<code>number[]</code>
 
|<code>math.min(1, -1)</code> -> {{#invoke:WikiFunctions|lua|math|min|1|-1}}<br/><code>math.min(9, 8, 2, 5.5)</code> -> {{#invoke:WikiFunctions|lua|math|min|9|8|2|5.5}}
 
|Returns the smallest number of given values.
 
|-
 
|class="code"|{{A|math.max|.max}}
 
|<code>number[]</code>
 
|<code>math.max(1, -1)</code> -> {{#invoke:WikiFunctions|lua|math|max|1|-1}}<br/><code>math.max(9, 8, 2, 5.5)</code> -> {{#invoke:WikiFunctions|lua|math|max|9|8|2|5.5}}
 
|Returns the greatest number of given values.
 
|-
 
|class="code"|{{A|math.floor|.floor}}
 
|<code>number</code>
 
|<code>math.floor(5.5)</code> -> {{#invoke:WikiFunctions|lua|math|floor|5.5}}<br/><code>math.floor(-5.5)</code> -> {{#invoke:WikiFunctions|lua|math|floor|-5.5}}
 
|Returns number rounded down to an integer.
 
|-
 
|class="code"|{{A|math.ceil|.ceil}}
 
|<code>number</code>
 
|<code>math.ceil(5.5)</code> -> {{#invoke:WikiFunctions|lua|math|ceil|5.5}}<br/><code>math.ceil(-5.5)</code> -> {{#invoke:WikiFunctions|lua|math|ceil|-5.5}}
 
|Returns number rounded up to an integer.
 
|-
 
|class="code"|{{A|math.modf|.modf}}
 
|<code>number</code>
 
|<code>math.modf(5.5)</code> -> '''5''', '''0.5'''<br/><code>math.modf(-5.5)</code> -> '''-5''', '''-0.5'''
 
|Returns number without decimal places, returns decimal places alone. The first returned value is equivalent to JavaScript's <code>trunc</code>.
 
|-
 
|class="code"|{{A|math.abs|.abs}}
 
|<code>number</code>
 
|<code>math.abs(5.5)</code> -> {{#invoke:WikiFunctions|lua|math|abs|5.5}}<br/><code>math.abs(-5.5)</code> -> {{#invoke:WikiFunctions|lua|math|abs|-5.5}}
 
|Returns positive form of number.
 
|-
 
|class="code"|{{A|math.random|.random}}
 
|((<code>max</code>) or (<code>min</code>, <code>max</code>)<br/><code>min</code><br/><code>max</code>
 
|<code>math.random()</code> -> {{#invoke:WikiFunctions|lua|math|random}}<br/><code>math.random(3)</code> -> {{#invoke:WikiFunctions|lua|math|random|3}}<br/><code>math.random(4, 5)</code> -> {{#invoke:WikiFunctions|lua|math|random|4|5}}
 
|When used without parameters, returns random number between 0 and 1. When used with first parameter, returns random integer between 1 and <code>max<code>. When used with two parameters, returns random integer between <code>min</code> and <code>max</code>.
 
|-
 
|class="code"|{{A|math.exp|.exp}}
 
|<code>number</code>
 
|<code>math.exp(1) -> '''{{#invoke:WikiFunctions|lua|math|exp|1}}'''</code>
 
|Returns the exponential function <em>e<sup>x</sup></em> (inverse of the natural logarithm).
 
|-
 
|class="code"|{{A|math.log|.log}}
 
|<code>number</code>
 
|<code>math.log(math.exp(1))</code> -> '''1'''
 
|Returns the natural logarithm (inverse of the exponential function <em>e<sup>x</sup></em>).
 
|-
 
|class="code"|{{A|math.deg|.deg}}
 
|<code>number</code>
 
|<code>math.deg(math.pi / 2)</code> -> '''{{#invoke:WikiFunctions|lua|math|deg|{{#invoke:WikiFunctions|lua|math|pi}}/2}}'''
 
|Converts a radian angle to degrees.
 
|-
 
|class="code"|{{A|math.rad|.rad}}
 
|<code>number</code>
 
|<code>math.rad(90)</code> -> '''{{#invoke:WikiFunctions|lua|math|rad|90}}'''
 
|Converts a degree angle to radians.
 
|-
 
|class="code"|{{A|math.sin|.sin}}
 
|<code>number</code>
 
|<code>math.sin(math.pi / 2)</code> -> '''{{#invoke:WikiFunctions|lua|math|sin|{{#invoke:WikiFunctions|lua|math|pi}}/2}}'''
 
|Returns the sine of a radian angle.
 
|-
 
|class="code"|{{A|math.cos|.cos}}
 
|<code>number</code>
 
|<code>math.cos(math.pi)</code> -> '''{{#invoke:WikiFunctions|lua|math|cos|{{#invoke:WikiFunctions|lua|math|pi}}}}'''
 
|Returns the cosine of a radian angle.
 
|-
 
|class="code"|{{A|math.tan|.tan}}
 
|<code>number</code>
 
|<code>math.tan(math.pi / 4)</code> -> '''{{#invoke:WikiFunctions|lua|math|tan|{{#invoke:WikiFunctions|lua|math|pi}}/4}}'''
 
|Returns the tangent of a radian angle.
 
|-
 
|class="code"|{{A|math.asin|.asin}}
 
|<code>number</code>
 
|<code>math.asin(0)</code> -> '''{{#invoke:WikiFunctions|lua|math|asin|0}}'''
 
|Returns the arcsine (inverse sine) of a ratio, as a radian angle.
 
|-
 
|class="code"|{{A|math.acos|.acos}}
 
|<code>number</code>
 
|<code>math.acos(0)</code> -> '''{{#invoke:WikiFunctions|lua|math|acos|0}}'''
 
|Returns the arccosine (inverse cosine) of a ratio, as a radian angle.
 
|-
 
|class="code"|{{A|math.atan|.atan}}
 
|<code>number</code>
 
|<code>math.atan(0)</code> -> '''{{#invoke:WikiFunctions|lua|math|atan|0}}'''
 
|Returns the arctangent (inverse tangent) of a ratio, as a radian angle. Ignores signs of angles.
 
|-
 
|class="code"|{{A|math.atan2|.atan2}}
 
|<code>number1</code><br/><code>number2</code>
 
|<code>math.atan2(0,-1)</code> -> '''{{#invoke:WikiFunctions|lua|math|atan2|0|-1}}'''
 
|Returns the arctangent (inverse tangent) of two numbers in a ratio as a radian angle. Does not ignore signs.
 
|-
 
|class="code"|{{A|math.sinh|.sinh}}
 
|<code>number</code>
 
|<code>math.sinh(math.log(2))</code> -> '''0.75'''
 
|Returns the hyperbolic sine of a number.
 
|-
 
|class="code"|{{A|math.cosh|.cosh}}
 
|<code>number</code>
 
|<code>math.cosh(math.log(2))</code> -> '''{{#invoke:WikiFunctions|lua|math|cosh|
 
{{#invoke:WikiFunctions|lua|math|log|2}}}}'''
 
|Returns the hyperbolic cosine of a number.
 
|-
 
|class="code"|{{A|math.tanh|.tanh}}
 
|<code>number</code>
 
|<code>math.tanh(math.log(2))</code> -> '''{{#invoke:WikiFunctions|lua|math|tanh|
 
{{#invoke:WikiFunctions|lua|math|log|2}}}}'''
 
 
|Returns the hyperbolic tangent of a number.
 
|-
 
|class="code"|{{A|math.frexp|.frexp}}
 
|<code>number</code>
 
|<code>math.frexp(8)</code> -> '''0.5''', '''4'''
 
|Normalizes a number, splitting it into the form base * 2 ^ exp. The base must fall into the interval [.5, 1].
 
|-
 
|class="code"|{{A|math.ldexp|.ldexp}}
 
|<code>number[]</code>
 
|<code>math.ldexp(0.5, 4)</code> -> '''{{#invoke:WikiFunctions|lua|math|ldexp|0.5|4}}'''
 
|Denormalizes a 2-tuple, returning base * 2 ^ exp. Only works if base falls into interval [.5, 1].
 
|}
 
 
===mw===
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|mw.log|.log}}
 
|<code>values[]</code>
 
| -
 
|Prints values to console. Safer than [[#print|<code>print</code>]] as it does not cause script errors when used in modules.
 
|-
 
|class="code"|{{A|mw.clone|.clone}}
 
|<code>value</code>
 
| -
 
|Returns a copy of the input value. This means that tables are re-created so two identical tables exist rather than there being two places referencing a single table.
 
|-
 
|class="code"|{{A|mw.getLanguage|.getLanguage}}
 
|<code>langcode</code> - Language code, e.g. "en"
 
| -
 
|Returns [[#Language|Language]] object for specified language code. Most of the time <code>en</code> will be desired so more appropriate to use <code>[[#mw.message.getDefaultLanguage|mw.message.getDefaultLanguage]]</code>.
 
|-
 
|class="code"|{{A|mw.getContentLanguage|.getContentLanguage}}
 
| -
 
| -
 
|Returns <code>Language</code> object for wiki's default language (en).
 
|-
 
|class="code"|{{A|mw.getCurrentFrame|.getCurrentFrame}}
 
| -
 
| -
 
|Returns <code>Frame</code> object for the {{tl|#invoke}} call.
 
|-
 
|class="code"|{{A|mw.loadData|.loadData}}
 
|<code>pagename</code> - Name of Module page
 
| -
 
|Returns returned readonly functionless <code>table</code> from called Module page. Data stored after first call are not recalled.
 
|-
 
|class="code"|{{A|mw.allToString|.allToString}}
 
|<code>values[]</code>
 
|<code>mw.allToString(true, false, 5, nil, 4, function() end)</code> -> "true", "false", "5", "nil", "4", "function"
 
|Returns all arguments as string values.
 
|-
 
|class="code"|{{A|mw.executeFunction|.executeFunction}}
 
|<code>function</code>
 
| -
 
|Returns given function with <code>frame</code> arguments as its arguments and returns the values with multiple-return values concatenated to a single value.
 
|-
 
|class="code"|{{A|mw.executeModule|.executeModule}}
 
|<code>function</code>
 
| -
 
|Safely executes a function without the function being able to modify the environment, such as globals.
 
|}
 
 
====<code>mw.text</code>====
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|mw.text.trim|.trim}}
 
|<code>string</code><br/><code>char</code> - String list of chars to trim (default: whitespace characters)
 
|mw.text.trim(" aha ") -> "'''{{#invoke:WikiFunctions|lua|mw|text|trim|" aha "}}'''"<br/>mw.text.trim("owcowcowo", "ow") -> "'''{{#invoke:WikiFunctions|lua|mw|text|trim|"owcowcowo"|"ow"}}'''"
 
|Returns string with removed consecutive members of <code>char</code> from start and end.
 
|-
 
|class="code"|{{A|mw.text.truncate|.truncate}}
 
|<code>string</code><br/><code>length</code> - Number of characters<br/><code>ellipsis</code> - String truncate symbol (default: [[MediaWiki:Ellipsis|{{MediaWiki:Ellipsis}}]])<br/><code>adjustLength</code> - Boolean for including ellipsis in <code>length</code> (default: <code>false</code>)
 
|mw.text.truncate("cowowowow", 5) -> '''{{#invoke:WikiFunctions|lua|mw|text|truncate|"cowowowow"|5}}'''<br/>mw.text.truncate("cowowowow", 6) -> {{#invoke:WikiFunctions|lua|mw|text|truncate|"cowowowow"|6}}<br/>mw.text.truncate("cowowowow", 5, "(...)") -> {{#invoke:WikiFunctions|lua|mw|text|truncate|"cowowowow"|5|"(...)"}}<br/>mw.text.truncate("cowowowow", 5, nil, true) -> {{#invoke:WikiFunctions|lua|mw|text|truncate|"cowowowow"|5|nil|true}}
 
|Returns string with characters longer than length removed.
 
|-
 
|class="code"|{{A|mw.text.listToText|.listToText}}
 
|<code>table</code><br/><code>separator</code> (default: ", ")<br/><code>conjunction</code> - Last separator (default: " and ")
 
|mw.text.listToText({"a", 5, "b"}) -> '''{{#invoke:WikiFunctions|lua|mw|text|listToText|{"a", 5, "b"} }}'''<br/>mw.text.listToText({"a", 5, "b"}, "; ", "; or ") -> '''{{#invoke:WikiFunctions|lua|mw|text|listToText|{"a", 5, "b"}|"; "|"; or "}}'''
 
|Returns string of table member values separated by delimiter, and uses <code>conjunction</code> on rightmost join.
 
|-
 
|class="code"|{{A|mw.text.split|.split}}
 
|<code>string</code><br/><code>delimiter</code> - Substring to split string at<br/><code>code</code> - Boolean for plaintext delimiter (default: <code>true</code>)
 
|<code>mw.text.split("a@b@c@", "@"))</code> -> {{#invoke:WikiFunctions|lua|mw|text|split|"a@b@c@"|"@"}}
 
|Returns auto-indexed table of substrings split from string by delimiter. If <code>plain</code> is true then empty string values are not added. Uses [http://lua-users.org/wiki/PatternsTutorial Lua Patterns] if <code>plain</code> is <code>false</code>.
 
|-
 
|class="code"|{{A|mw.text.encode|.encode}}
 
|<code>string</code><br/><code>chars</code> - String list of chars to encode (default: "<code><>&\"'{{foot|&nbsp;|non-break space}}</code>")
 
|mw.text.encode("Final Fantasy Wiki's") -> '''{{#invoke:WikiFunctions|lua|mw|text|encode|"Final Fantasy Wiki's"}}'''<br/>mw.text.encode("Final Fantasy Wiki's", "ia") -> '''{{#invoke:WikiFunctions|lua|mw|text|encode|"Final Fantasy Wiki's"|"ia"}}'''
 
|Returns <code>string</code> with members of <code>char</code> replaced by HTML entity references.
 
|-
 
|class="code"|{{A|mw.text.decode|.decode}}
 
|<code>string</code><br/><code>namedrefs</code> - Boolean for including named references (default: <code>false</code>)
 
|mw.text.decode("&amp;quot;&amp;#123;{-&amp;#124;left}&amp;#125;&amp;quot;") -> &amp;quot;&#123;{-|left}}&amp;quot;<br/>mw.text.decode(&amp;quot;"&amp;#123;{-&amp;#124;left}&amp;#125;&amp;quot;", true) -> "&#123;{-|left}}"
 
|Returns string with entity references (and optionally some named references) resolved as literal characters. Named references include <code>&amp;lt;</code>, <code>&amp;gt;</code>, <code>&amp;amp;</code>, <code>&amp;quot;</code>, and <code>&amp;nbsp;</code>.
 
|-
 
|class="code"|{{A|mw.text.nowiki|.nowiki}}
 
|<code>string</code>
 
|mw.text.nowiki("<nowiki>{{-|left}}</nowiki>") -> &amp;#123;&amp;#123;-&amp;#124;left&amp;#125;&amp;#125;
 
|Returns HTML entity reference escaped <code>string</code>.
 
|-
 
|class="code"|{{A|mw.text.tag|.tag}}
 
|<code>tagname</code> - String tag<br/><code>attributes</code> - Table named-index attributes and values (default: <code>{}</code>)<br/><code>content</code> (optional)
 
|mw.text.tag("p") -> &lt;p><br/>mw.text.tag("p", {class = "para", style = "font-weight: bold"}, "lol") -> &lt;p style="font-weight: bold" class="para">lol</p><br/>mw.text.tag("input", {type = "submit", value = "Save", id = "btnSave", disabled = true}, false) -> &lt;input value="Save" type="submit" disabled id="btnSave" />
 
|Returns string HTML tag of tagname with given attributes values and content. If <code>content</code> is <code>nil</code> then only opening tag returned. If <code>content</code> is <code>false</code> then a self-closed tag is returned. A key paired with a value of <code>true</code> in the <code>attributes</code> table has a valueless parameter added.
 
|}
 
 
====<code>mw.uri</code>====
 
Functions related to URLs and the <code>URI</code> object.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|mw.uri.parseQueryString|.parseQueryString}}
 
|<code>string</code> - [[User:JBed/Help:URL parameters|Query string]]
 
|<code>mw.uri.parseQueryString("?action=edit&tester=true")</code> -> {{#invoke:WikiFunctions|lua|mw|uri|parseQueryString|"?action{{=}}edit&tester{{=}}true"}}<br/><code>mw.uri.parseQueryString("css")</code> -> {{#invoke:WikiFunctions|lua|mw|uri|parseQueryString|"css"}}
 
|Returns query string as table. Keys without values have their value set to <code>false</code>.
 
|-
 
|class="code"|{{A|mw.uri.buildQueryString|.buildQueryString}}
 
|<code>table</code>
 
|<code>mw.uri.buildQueryString({action="edit", tester="true"})</code> -> '''{{#invoke:WikiFunctions|lua|mw|uri|buildQueryString|{action{{=}}"edit", tester{{=}}"true"} }}'''<br/><code>mw.uri.buildQueryString({css=false})</code> -> '''{{#invoke:WikiFunctions|lua|mw|uri|buildQueryString|{css{{=}}false} }}'''
 
|Returns query string from table. Key set to <code>false</code> just returns key name.
 
|-
 
|class="code"|{{A|mw.uri.encode|.encode}}
 
|<code>string</code><br/><code>encmode</code> string method of encoding of spaces (default: "QUERY")
 
|mw.uri.encode("It's good") -> {{#invoke:WikiFunctions|lua|mw|uri|encode|"It's good"}}<br/>mw.uri.encode("It's good", "path") -> {{#invoke:WikiFunctions|lua|mw|uri|encode|"It's good"|"path"}}<br/>mw.uri.encode("It's good", "WIKI") -> {{#invoke:WikiFunctions|lua|mw|uri|encode|"It's good"|"WIKI"}}
 
|Encodes string for URLs. <code>encmode</code> of <code>"QUERY"</code> is for referencing a page name in a query, <code>"WIKI"</code> is for referencing a wiki page name, and <code>"PATH"</code> is for a non-wiki path.
 
|-
 
|class="code"|{{A|mw.uri.decode|.decode}}
 
|<code>string</code><br/><code>encmode</code> string method of decoding (default: "QUERY")
 
|mw.uri.decode("{{#invoke:WikiFunctions|lua|mw|uri|encode|"It's good"}}") -> "It's good"<br/>mw.uri.decode("{{#invoke:WikiFunctions|lua|mw|uri|encode|"It's good"|"path"}}", "path") -> It's good<br/>mw.uri.decode("{{#invoke:WikiFunctions|lua|mw|uri|encode|"It's good"|"WIKI"}}", "WIKI") -> It's good
 
|Encodes string for URLs. <code>encmode</code> of <code>"QUERY"</code> is for referencing a page name in a query, <code>"WIKI"</code> is for referencing a wiki page name, and <code>"PATH"</code> is for a non-wiki path.
 
|-
 
|class="code"|{{A|mw.uri.anchorEncode|.anchorEncode}}
 
|<code>string</code>
 
|mw.uri.anchorEncode("Aeris's House 1f.") -> {{#invoke:WikiFunctions|lua|mw|uri|anchorEncode|"Aeris's House 1f."}}
 
|Encodes string for URL <code>hash</code> value.
 
|-
 
|class="code"|{{A|mw.uri.fullUrl|.fullUrl}}
 
|<code>pagename</code> - String<br/><code>query</code> - string or table query (optional)
 
|<code>mw.uri.pagename("Help:Lua")</code> -> {{#invoke:WikiFunctions|lua|mw|uri|fullUrl|"Help:Lua"}}<br/><code>mw.uri.pagename("Help:Lua", "action=edit")</code> -> {{#invoke:WikiFunctions|lua|mw|uri|fullUrl|"Help:Lua"|"action{{=}}edit"}}<br/><code>mw.uri.pagename("Help:Lua", { usetheme = "zidane" )</code> -> {{#invoke:WikiFunctions|lua|mw|uri|fullUrl|"Help:Lua"|"usetheme{{=}}zidane"}}
 
|Returns full URL from page name and string query. Same as <code>canonicalUrl</code> as far as I know (though I'm sure there's a difference)
 
|-
 
|class="code"|{{A|mw.uri.localUrl|.localUrl}}
 
|<code>pagename</code> - String<br/><code>query</code> - string or table query (optional)
 
|<code>mw.uri.pagename("Help:Lua")</code> -> {{#invoke:WikiFunctions|lua|mw|uri|localUrl|"Help:Lua"}}<br/><code>mw.uri.pagename("Help:Lua", "action=edit")</code> -> {{#invoke:WikiFunctions|lua|mw|uri|localUrl|"Help:Lua"|"action{{=}}edit"}}<br/><code>mw.uri.pagename("Help:Lua", { usetheme = "zidane" )</code> -> {{#invoke:WikiFunctions|lua|mw|uri|localUrl|"Help:Lua"|"usetheme{{=}}zidane"}}
 
|Returns URI object for local URL (no <code>host</code> or <code>port</code> parameters) from page name and string query.
 
|-
 
|class="code"|{{A|mw.uri.validate|.validate}}
 
|<code>table</code> -
 
|<code>mw.uri.validate({"A"})</code> -> '''{{#invoke:WikiFunctions|lua|mw|uri|validate|{"A"} }}'''<br/><code>mw.uri.validate({path = ""})</code> -> '''{{#invoke:WikiFunctions|lua|mw|uri|validate|{path {{=}} ""} }}'''
 
|Returns boolean for the valid table being convertible to URI object.
 
|-
 
|class="code"|{{A|mw.uri.new|.new}}
 
|<code>table</code>
 
| -
 
|Returns URI object from table.
 
|}
 
 
====<code>mw.ustring</code>====
 
<pre>
 
ustring = { byteoffset = function, isutf8 = function, match = function, gmatch = function, maxPatternLength = 10000, upper = function, gsub = function, format = function, lower = function, sub = function, codepoint = function, find = function, char = function, byte = function, gcodepoint = function, rep = function, len = function, toNFC = function, maxStringLength = 2097152, toNFD = function }
 
</pre>
 
 
====<code>mw.language</code>====
 
Related to the <code>Language</code> object.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|mw.language.fetchLanguageName|.fetchLanguageName}}
 
|<code>langcode</code> - string language code
 
|mw.language.fetchLanguageName("de") -> <strong>{{#invoke:WikiFunctions|lua|mw|language|fetchLanguageName|"de"}}</strong><br/>mw.language.fetchLanguageName("bwab2")<strong>{{#invoke:WikiFunctions|lua|mw|language|fetchLanguageName|"bwab2"}}</strong>
 
|Returns language name of input language code. If does not match language used in software, returns empty string.
 
|-
 
|class="code"|{{A|mw.language.isValidBuiltInCode|.isValidBuiltInCode}}
 
|<code>langcode</code> - string language code
 
|mw.language.isValidBuiltInCode("en") -> {{#invoke:WikiFunctions|lua|mw|language|isValidBuiltInCode|"qqx"}}<br/>mw.language.isValidBuiltInCode("bwab2") -> {{#invoke:WikiFunctions|lua|mw|language|isValidBuiltInCode|"bwab2"}}<br/>mw.language.isValidBuiltInCode("@lol") -> {{#invoke:WikiFunctions|lua|mw|language|isValidBuiltInCode|"@lol"}}
 
|Returns boolean for string being a technically acceptable name for a language code in the MediaWiki software, regardless of whether it is one. Alternate <code>mw.language.isValidCode</code> also exists but it accepts values that would not be acceptable as MediaWiki language code names.
 
|-
 
|class="code"|{{A|mw.language.new|.new}}
 
|<code>langcode</code> - string language code
 
| -
 
|Returns [[#mw.Language|mw.Language]] object for specified language code. Most of the time <code>en</code> will be desired so more appropriate to use <code>[[#mw.message.getDefaultLanguage|mw.message.getDefaultLanguage]]</code>.
 
|}
 
 
====<code>mw.message</code>====
 
message = { rawParam = function, getDefaultLanguage = function, newFallbackSequence = function, numParam = function, new = function }
 
 
====<code>mw.title</code>====
 
<code>mw.title</code> are functions related to the [[#Title]] object which contain details about a page on the wiki. A new Title object is created with <code>mw.title.new</code>.
 
 
Using titles is expensive as it has to look up and return a page from the database.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|mw.title.new|.new}}
 
|(<code>id</code> - page ID)<br/>(<code>fulltitle</code> - full page title)<br/>(<code>title</code> - page title, <code>nsid</code> - namespace ID)<br/>(<code>title</code> - page title, <code>ns</code> - namespace)
 
|mw.title.new(3) -> [[Final Fantasy Wiki]]<br/><!--
 
-->mw.title.new("Project:About") -> [[{{ns:4}}:About]]<br/><!--
 
-->mw.title.new("About, "Project"") -> [[{{ns:4}}:About]]<br/><!--
 
-->mw.title.new("Project:About", 4) -> [[{{ns:4}}:About]]
 
|Returns [[#Title|Title]] object of given page from ID, full title, or name and namespace.
 
|-
 
|class="code"|{{A|mw.title.getCurrentTitle|.getCurrentTitle}}
 
| -
 
|{{doclua|mw.title.getCurrentTitle()}}
 
|Returns [[#Title|Title]] object of current page.
 
|-
 
|class="code"|{{A|mw.title.getCurrentTitle|.equals}}
 
| -
 
|{{doclua|mw.title.equals(mw.title.new(3), mw.title.new("Final Fantasy Wiki"))}}<br/>{{doclua|mw.title.equals(mw.title.new(2), mw.title.new("Final Fantasy Wiki"))}}
 
|Returns boolean for two Title objects being for the same page.
 
|}
 
 
====<code>mw.site</code>====
 
Site contains properties about the wiki's software and set-up. The [[#mw.site.stats|<code>stats</code>]] sub-table contains further properties and methods regarding stats.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Property
 
!style="width:20%"|Output
 
!Description
 
|-
 
|class="code"|{{A|mw.site.siteName|.siteName}}
 
|{{#invoke:WikiFunctions|lua|mw|site|siteName}}
 
|Name of wiki.
 
|-
 
|class="code"|{{A|mw.site.currentVersion|.currentVersion}}
 
|{{#invoke:WikiFunctions|lua|mw|site|currentVersion}}
 
|Version of MediaWiki used by wiki.
 
|-
 
|class="code"|{{A|mw.site.server|.server}}
 
|{{#invoke:WikiFunctions|lua|mw|site|server}}
 
|Wiki's server/URL.
 
|-
 
|class="code"|{{A|mw.site.stylePath|.stylePath}}
 
|{{#invoke:WikiFunctions|lua|mw|site|stylePath}}
 
|URL path for skin files.
 
|-
 
|class="code"|{{A|mw.site.scriptPath|.scriptPath}}
 
|{{#invoke:WikiFunctions|lua|mw|site|scriptPath}}
 
|URL path for script files.
 
|-
 
|class="code"|{{A|mw.site.namespaces|.namespaces}}
 
| -
 
|Table of all namespaces as [[#Namespace|Namespace objects]].
 
|-
 
|class="code"|{{A|mw.site.contentNamespaces|.contentNamespaces}}
 
| -
 
|Table of all content namespaces as [[#Namespace|Namespace objects]].
 
|-
 
|class="code"|{{A|mw.site.subjectNamespaces|.subjectNamespaces}}
 
| -
 
|Table of all subject namespaces as [[#Namespace|Namespace objects]].
 
|-
 
|class="code"|{{A|mw.site.talkNamespaces|.talkNamespaces}}
 
| -
 
|Table of all talk namespaces as [[#Namespace|Namespace objects]].
 
|}
 
 
=====<code>mw.site.stats</code>=====
 
======Properties======
 
These properties are not technically properties of <code>mw.site.stats</code>, they are available from it due to a [[#Metatable|metatable]].
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Property
 
!style="width:20%"|Output
 
!Description
 
|-
 
|class="code"|{{A|mw.site.stats.users|.users}}
 
|{{#invoke:WikiFunctions|lua|mw|site|stats|users}}
 
|Number of registered Wikia users.
 
|-
 
|class="code"|{{A|mw.site.stats.activeUsers|.activeUsers}}
 
|{{#invoke:WikiFunctions|lua|mw|site|stats|activeUsers}}
 
|Number of {{lcfirst:{{int:Statistics-users-active-desc/en|30}}}}.
 
|-
 
|class="code"|{{A|mw.site.stats.pages|.pages}}
 
|{{#invoke:WikiFunctions|lua|mw|site|stats|pages}}
 
|Total number of pages on the wiki.
 
|-
 
|class="code"|{{A|mw.site.stats.articles|.articles}}
 
|{{#invoke:WikiFunctions|lua|mw|site|stats|articles}}
 
|Total number of articles and disambiguation pages on the wiki.
 
|-
 
|class="code"|{{A|mw.site.stats.pages|.pages}}
 
|{{#invoke:WikiFunctions|lua|mw|site|stats|pages}}
 
|Total number of pages on the wiki.
 
|-
 
|class="code"|{{A|mw.site.stats.files|.files}}
 
|{{#invoke:WikiFunctions|lua|mw|site|stats|files}}
 
|Total number of files on the wiki.
 
|-
 
|class="code"|{{A|mw.site.stats.edits|.edits}}
 
|{{#invoke:WikiFunctions|lua|mw|site|stats|edits}}
 
|Total number of edits made to the wiki.
 
|}
 
 
======Functions======
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|mw.site.stats.pagesInCategory|.pagesInCategory}}
 
|<code>category</code> - string category name<br/><code>pagetype</code> (default: "<code>all</code>")
 
|<code>mw.site.stats.pagesInCategory("Articles for Speedy Deletion")</code> -> {{#invoke:WikiFunctions|lua|mw|site|stats|pagesInCategory|"Articles for Speedy Deletion"}}<br/><!--
 
--><code>mw.site.stats.pagesInCategory("Articles for Speedy Deletion", "files")</code> -> {{#invoke:WikiFunctions|lua|mw|site|stats|pagesInCategory|"Articles for Speedy Deletion"|"files"}}<br/><!--
 
--><code>mw.site.stats.pagesInCategory("Articles for Speedy Deletion", "*")</code> -> {{#invoke:WikiFunctions|lua|mw|site|stats|pagesInCategory|"Articles for Speedy Deletion"|"*"}}
 
|Returns number of pages of <code>pagetype</code> from Category:<code>category</code>. <code>pagetype</code> can be <code>"files"</code> (File namespace), <code>"subcats"</code> (Category namespace), <code>"pages"</code> (remaining namespaces), and <code>"all"</code> (a combination of the previous three). If <code>pagetype</code> is <code>"*"</code> then a table is returned with all values.
 
|-
 
|class="code"|{{A|mw.site.stats.pagesInNamespace|.pagesInNamespace}}
 
|<code>namespace</code> - number namespace id
 
|<code>mw.site.stats.pagesInNamespace(0)</code> -> {{#invoke:WikiFunctions|lua|mw|site|stats|pagesInNamespace|0}}
 
|Returns number of pages in namespace.
 
|-
 
|class="code"|{{A|mw.site.stats.usersInGroup|.usersInGroup}}
 
|<code>group</code> - string group name
 
|<code>mw.site.stats.usersInGroup("designer")</code> -> {{#invoke:WikiFunctions|lua|mw|site|stats|usersInGroup|"designer"}}
 
|Returns number of users in usergroup.
 
|}
 
 
====<code>mw.html</code>====
 
<code>mw.html</code> only has one function, the <code>create</code> function. The <code>create</code> function is used to create a new instance of the <code>HTML</code> class.
 
 
:<source lang="lua" class="inline">mw.html.create( </source> ''tag'' <source lang="lua" class="inline"> )</source>
 
 
For example:
 
:<source lang="lua" class="inline">mw.html.create("div")</source> -> '''&lt;div></div>'''
 
:<source lang="lua" class="inline">mw.html.create("hr")</source> -> '''&lt;hr />'''
 
 
:<source lang="lua" class="inline">mw.html.create( </source> <code>''tag''</code> <source lang="lua" class="inline">, </source><code>''args''</code><source lang="lua" class="inline"> )</source>
 
 
<code>args</code> is for tables with specific properties. There is only one worthwhile property, the <code>selfClosing</code> boolean to make a tag close at the end. The class automatically does this for tags that self-close, (e.g. {{tag|br|/}}) however this allows tag that do not have to be self-closing to manually do this. Though it should be noted that it is not possibly to set this value to false to turn a self-closing tag into a non-self-closing tag. So {{tag|hr|/}} and {{tag|br|/}} cannot be used as tag pairs.
 
 
For example:
 
:<source lang="lua" class="inline">mw.html.create("div", { selfClosing = true })</source> -> '''&lt;div />'''
 
:<source lang="lua" class="inline">mw.html.create("hr", { selfClosing = false })</source> -> '''&lt;hr />'''
 
 
===[[Module:String]]===
 
Module:String is meant to override [[#string|string]] as it incorporates the functions of the string library while supplying additional string functions.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|string.trim|.trim}}<br/>{{A|String:trim|:trim}}
 
|colspan="3"|Contains [[#mw.text.trim|<code>mw.text.trim</code>]]. Enables use as a method.
 
|-
 
|class="code"|{{A|string.split|.split}}<br/>{{A|String:split|:split}}
 
|<code>string</code><br/><code>delimiter</code> - Substring to split string at.<br/><code>removeemptyentries</code> - Boolean for removing empty entries (default: false).<br/><code>trimentries</code> - Boolean for trimming trailing whitespace (default: false).
 
|string.split("@A@B@C@", "@") → {{#invoke:WikiFunctions|lua|string|split|"@A@B@C@"|"@"}}<br/><!--
 
-->string.split("@A@B@C@", "@", true) → {{#invoke:WikiFunctions|lua|string|split|"@A@B@C@"|"@"|true}}<br/><!--
 
-->string.split("@A@B @ @ C@", "@", true, true) → {{#invoke:WikiFunctions|lua|string|split|"@A@B @ @ C@"|"@"|true|true}}
 
|Returns auto-indexed table of substrings split from <code>string</code> by <code>delimiter</code>. If <code>removemptyentries</code> is true then empty string values are not added. If <code>trimentries</code> is true then removes trailing whitespace.
 
|-
 
|class="code"|{{A|string.tochartable|.tochartable}}<br/>{{A|String:tochartable|:tochartable}}
 
|<code>string</code>
 
|string.tochartable("okay") → {{#invoke:WikiFunctions|lua|string|tochartable|"okay"}}
 
|Returns auto-indexed table of characters within string.
 
|-
 
|class="code"|{{A|string.replace|.replace}}<br/>{{A|String:replace|:replace}}
 
|<code>string</code><br/><code>search</code> - string replaced<br/><code>replace</code> - string replacement
 
|string.replace("ABCD", "BC", "AB") → '''{{#invoke:WikiFunctions|lua|string|replace|"ABCD"|"BC"|"AB"}}'''
 
|Returns <code>string</code> with instances of <code>search</code> substring replaced by <code>replace</code> substring. No Lua patterns.
 
|-
 
|class="code"|{{A|string.contains|.contains}}<br/>{{A|String:contains|:contains}}
 
|<code>string</code><br/><code>search</code>
 
|string.contains("ABCD", "BC") → '''{{#invoke:WikiFunctions|lua|string|contains|"ABCD"|"BC"}}'''<br/>string.contains("ABCD", "bc") → '''{{#invoke:WikiFunctions|lua|string|contains|"ABCD"|"bc"}}'''
 
|Returns boolean for <code>string</code> containing <code>search</code> substring.
 
|-
 
|class="code"|{{A|string.startswith|.startswith}}<br/>{{A|String:startswith|:startswith}}
 
|<code>string</code><br/><code>search</code>
 
|string.startswith("ABCD", "AB") → '''{{#invoke:WikiFunctions|lua|string|startswith|"ABCD"|"AB"}}'''<br/>string.startswith("ABCD", "BC") → '''{{#invoke:WikiFunctions|lua|string|startswith|"ABCD"|"BC"}}'''
 
|Returns boolean for <code>string</code> beginning with <code>search</code> substring.
 
|-
 
|class="code"|{{A|string.endswith|.endswith}}<br/>{{A|String:endswith|:endswith}}
 
|<code>string</code><br/><code>search</code>
 
|string.endswith("ABCD", "CD") → '''{{#invoke:WikiFunctions|lua|string|endswith|"ABCD"|"CD"}}'''<br/>string.endswith("ABCD", "BC") → '''{{#invoke:WikiFunctions|lua|string|endswith|"ABCD"|"BC"}}'''
 
|Returns boolean for <code>string</code> ending with <code>search</code> substring.
 
|-
 
|class="code"|{{A|string.lettersequence|.lettersequence}}
 
|<code>number</code>
 
|string.lettersequence(1) → '''{{#invoke:WikiFunctions|lua|string|lettersequence|1}}'''<br/>string.lettersequence(27) → '''{{#invoke:WikiFunctions|lua|string|lettersequence|27}}'''<br/>string.lettersequence(128) → '''{{#invoke:WikiFunctions|lua|string|lettersequence|128}}'''
 
|Returns letter sequence from number. Essentially converts a number to a pseudo-base26, where the numbers are letters A-Z.
 
|}
 
 
===[[Module:Table]]===
 
Designed to override <code>[[#table|table]]</code> by adding functions. <code>pack</code> and <code>unpack</code> are functions that exist in more modern versions of Lua.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|table.contains|.contains}}
 
|<code>table</code><br/><code>search</code>
 
|table.contains({"A", B = "CC"}, "CC") → '''{{#invoke:WikiFunctions|lua|table|contains|{"A", B {{=}} "CC"}|"CC"}}'''<br/>table.contains({"A", B {{=}} "CC"}, "C") → '''{{#invoke:WikiFunctions|lua|table|contains|{"A", B {{=}} "CC"}|"C"}}'''
 
|Returns boolean for a member of <coed>table</code> matching <code>search</code> value.
 
|-
 
|class="code"|{{A|table.keys|.keys}}
 
|<code>table</code>
 
|table.keys({"A", B = "C"}) → {{#invoke:WikiFunctions|lua|table|keys|{"A", B {{=}} "C"} }}
 
|Returns auto-indexed table of <code>table</code>'s keys.
 
|-
 
|class="code"|{{A|table.pack|.pack}}
 
|<code>values[]</code>
 
|table.pack("A", "B", "C") → {{#invoke:WikiFunctions|lua|table|pack|"A"|"B"|"C"}}
 
|Returns auto-indexed table of values with <code>n</code> property containing number of parameters. Useful for catching all the values returned by multi-value returning functions.
 
|-
 
|class="code"|{{A|table.unpack|.unpack}}
 
|<code>table</code><br/><code>start</code> - From index (default: 1)<br/><code>end</code> - To index (default: <code>#table</code>)
 
|table.unpack({"A", "B", "C"}) → '''A''', '''B''', '''C'''<br/>table.unpack({"A", "B", "C"}, 2) → '''B''', '''C'''<br/>table.unpack({"A", "B", "C"}, 1, 2) → '''A''', '''B'''
 
|Returns table values from start index to index as multiple values. Useful to print a table's values.
 
|-
 
|class="code"|{{A|table.tostring|.tostring}}
 
|<code>table</code>
 
|table.tostring({"A", "B", "C"}) → '''{{#invoke:WikiFunctions|lua|table|tostring|{"A", "B", "C"} }}'''<br/>table.tostring({"A", "B", C = "D"}) → '''{{#invoke:WikiFunctions|lua|table|tostring|{"A", "B", C {{=}} "D"} }}'''
 
|Returns table values in a readable string format. Useful to print a table's values.
 
|}
 
 
===[[Module:Array]]===
 
Module:Array covers functions designed for auto-indexed tables. Array is also a class of object, and new arrays can be created with the <code>[[#array.new|array.new]]</code> function. An array object allows it to use array functions as methods, and sets its <code>[[#ffwiki.type|ffwiki.type]]</code> value to "array".
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|array.isarray|.isarray}}
 
|<code>object</code>
 
|array.isarray({"A", "B", "C"}) -> '''{{#invoke:WikiFunctions|lua|array|isarray|{"A", "B", "C"} }}'''<br/>array.isarray({"A", "B", C= "D"}) -> '''{{#invoke:WikiFunctions|lua|array|isarray|{"A", "B", C {{=}} "D"} }}'''<br/>array.isarray("ABC") -> '''{{#invoke:WikiFunctions|lua|array|isarray|"ABC"}}'''
 
|Returns boolean for object being auto-indexed table.
 
|-
 
|{{A|array.push|.push}}<br/>{{A|Array:push|:push}}
 
|<code>table</code><br/><code>value</code> - Value to add.
 
|array.push({"A"}, "B") → '''{{#invoke:WikiFunctions|lua|array|push|{"A"}|"B"}}''' (table: {"A", "B"})
 
|Adds value to end of table. Returns array's length.
 
|-
 
|{{A|array.unshift|.unshift}}<br/>{{A|Array:unshift|:unshift}}
 
|<code>table</code><br/><code>value</code> - Value to add.
 
|array.push({"A"}, "B") → '''{{#invoke:WikiFunctions|lua|array|unshift|{"A"}|"B"}}''' (table: {"B", "A"})
 
|Adds value to start of table. Returns array's length.
 
|-
 
|{{A|array.pop|.pop}}<br/>{{A|Array:pop|:pop}}
 
|<code>table</code>
 
|array.pop({"A", "B"}) → '''{{#invoke:WikiFunctions|lua|array|pop|{"A", "B"} }}''' (table: {"A"})
 
|Removes last member of table. Returns removed member's value.
 
|-
 
|{{A|array.shift|.shift}}<br/>{{A|Array:shift|:shift}}
 
|<code>table</code>
 
|array.shift({"A", "B"}) → '''"{{#invoke:WikiFunctions|lua|array|shift|{"A", "B"} }}"''' (table: {"B"})
 
|Removes first member of table. Returns removed member's value.
 
|-
 
|{{A|array.reverse|.reverse}}<br/>{{A|Array:reverse|:reverse}}
 
|<code>table</code>
 
|array.reverse({"A", "B"}) -> {{#invoke:WikiFunctions|lua|array|reverse|{"A", "B"} }}
 
|Reverses the order of members in the array. Also returns table.
 
|-
 
|{{A|array.concat|.concat}}<br/>{{A|Array:concat|:concat}}
 
|<code>table</code><br/><code>append[]</code> - Tables to concatenate to end.
 
|array.concat({"A"}, {"B", "C"}, {"D"}) → {{#invoke:WikiFunctions|lua|array|concat|{"A"}, {"B", "C"}, {"D"} }}
 
|Appends values from append tables to first table. Also returns table.
 
|-
 
|{{A|array.contains|.contains}}<br/>{{A|Array:contains|:contains}}
 
|<code>table</code><br/><code>search</code>
 
|array.contains({"AA", "BB", "CC"}, "AA") → '''{{#invoke:WikiFunctions|lua|array|contains|{"AA", "BB", "CC"}|"AA"}}''' }}'''<br/>array.contains({"AA", "BB", "CC"}, "A") → '''{{#invoke:WikiFunctions|lua|array|contains|{"AA", "BB", "CC"}|"A"}}'''
 
|Returns boolean for any member of <code>table</code> matching <code>search</code> value.
 
|-
 
|{{A|array.indexof|.indexof}}<br/>{{A|Array:indexof|:indexof}}
 
|<code>table</code><br/><code>value</code> - Value to find.
 
|array.indexof({"A", "B", "A"}, "A") → '''{{#invoke:WikiFunctions|lua|array|indexof|{"A", "B", "A"}|"A"}}'''
 
|Returns index of first member matching value.
 
|-
 
|{{A|array.lastindexof|.lastindexof}}<br/>{{A|Array:lastindexof|:lastindexof}}
 
|<code>table</code><br/><code>value</code> - Value to find.
 
|array.indexof({"A", "B", "A"}, "A") → '''{{#invoke:WikiFunctions|lua|array|lastindexof|{"A", "B", "A"}|"A"}}'''
 
|Returns index of last member matching value.
 
|-
 
|{{A|array.slice|.slice}}<br/>{{A|Array:slice|:slice}}
 
|<code>table</code><br/><code>start</code> - Start index. If negative counts back from end.<br/><code>end</code> - End index. If negative counts back from end (default: #table).
 
|array.slice({"A", "B", "C"}, 2) → {{#invoke:WikiFunctions|lua|array|slice|{"B", "C"}|2}}<br/>array.slice({"A", "B", "C"}, -1) → {{#invoke:WikiFunctions|lua|array|slice|{"A", "B", "C"}|-1}}<br/>array.slice({"A", "B", "C"}, 0, 2) → {{#invoke:WikiFunctions|lua|array|slice|{"A", "B", "C"}|0|2}}<br/>array.slice({"A", "B", "C"}, -2, -1) → {{#invoke:WikiFunctions|lua|array|slice|{"B", "C"}|-2|-1}}
 
|Returns table members from start position to end position. If values are negative, counts back from end of table.
 
|-
 
|{{A|array.foreach|.foreach}}<br/>{{A|Array:foreach|:foreach}}
 
|<code>table</code><br/><code>function</code> - Function to run (parameters: member value, member index, table).
 
|array.foreach({2, 1, 3}, function(a, b, c) c[b] = a + 1 end) → (table: {3, 2, 4})
 
|Runs function for each member of a table.
 
|-
 
|{{A|array.recursiveforeach|.recursiveforeach}}<br/>{{A|Array:push|:recursiveforeach}}
 
|<code>table</code><br/><code>function</code> - Function to run (parameters: member value, member index, table).
 
|array.recursiveforeach({2, {1, 3}}, function(a, b, c) c[b] = a + 1 end) → (table: {3, 2, 4})
 
|Runs function for each member of a table.
 
|-
 
|{{A|array.join|.join}}<br/>{{A|Array:join|:join}}
 
|<code>table</code><br/><code>delimiter</code> (default: empty string)<br/><code>last</code> - Last delimiter (default: <code>delimiter</code><br/><code>first</code> - Last delimiter (default: <code>delimiter</code>
 
|array.join({"A", "B"}, ", ") → '''{{#invoke:WikiFunctions|lua|array|join|{"A", "B"}|", "}}'''<br/>array.join({"A", "B", "C"}, ", ", ", and ") → '''{{#invoke:WikiFunctions|lua|array|join|{"A", "B", "C"}|", "|", and "}}'''<br/>array.join({"A", "B", "C"}, ", and ", nil, " and ") → '''"{{#invoke:WikiFunctions|lua|array|join|{"A", "B", "C"}|", and "|nil|" and "}}'''
 
|Returns string of table member values separated by delimiter.
 
|-
 
|{{A|array.tostring|.tostring}}<br/>{{A|Array:tostring|:tostring}}
 
|<code>table</code>
 
|array.tostring({"A", "B"}) - '''{{#invoke:WikiFunctions|lua|array|tostring|{"A", "B"} }}'''
 
|Returns table as readable string.
 
|-
 
|{{A|array.print|.print}}<br/>{{A|Array:print|:print}}
 
|<code>table</code>
 
|array.print({"A", "B"}) - '''{ "A", "B" }'''
 
|Prints table as readable string. Using global <code>print</code> will not print table values. Using print in a script called with {{tl|#invoke}} will cause a script error.
 
|-
 
|{{A|array.new|.new}}
 
|((<code>table</code>) or (<code>values[]</code>))
 
|array.new() -> { }:func[]<br/>array.new({"A", "B"}) -> { "A", "B" }:func[]<br/>array.new("A", "B") -> { "A", "B" }:func[]
 
|Creates instance of <code>Array</code> object. An <code>Array</code> object can utilize all the above functions besides <code>isarray</code> as functions, where the parameters are the same but the first parameter is omitted. For example, <code>''array'':shift()</code> removes the first member of the array, and <code>''array'':join(", ")</code> returns a string where the array's members are separated by a comma and space.
 
|}
 
 
===[[Module:FFWiki]]===
 
FFWiki covers miscellaneous commonly useful functions, including Lua-written versions of functions available in MediaWiki.
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|ffwiki.round|.round}}
 
|<code>number</code> - Number to round<br/><code>dp</code> - Decimal places (default: 0)
 
|ffwiki.round(10.5) -> '''{{#invoke:WikiFunctions|lua|ffwiki|round|10.5}}'''<br/>ffwiki.round(4.4444, 2) -> '''{{#invoke:WikiFunctions|lua|ffwiki|round|4.4444|2}}'''
 
|Returns a number rounded given number of decimal places.
 
|-
 
|class="code"|{{A|ffwiki.topercent|.topercent}}
 
|<code>numerator</code><br/><code>denominator</code> (default: 1)<br/><code>round</code> - Decimal places (default: 0)
 
|ffwiki.topercent(0.1) -> '''{{#invoke:WikiFunctions|lua|ffwiki|topercent|0.1}}'''<br/>ffwiki.topercent(1, 3) -> '''{{#invoke:WikiFunctions|lua|ffwiki|topercent|1|3}}'''<br/>ffwiki.topercent(1, 6, 2) -> '''{{#invoke:WikiFunctions|lua|ffwiki|topercent|1|6|2}}'''
 
|Returns string of fraction expressed as a percentage including symbol.
 
|-
 
|class="code"|{{A|ffwiki.cap|.cap}}
 
|<code>number</code><br/><code>minimum (default: -inf)</code><br/><code>maximum</code> (default: inf)
 
|ffwiki.cap(6, 7) -> '''{{#invoke:WikiFunctions|lua|ffwiki|cap|6|7}}'''<br/>ffwiki.cap(6, nil, 5) -> '''{{#invoke:WikiFunctions|lua|ffwiki|cap|6|nil|5}}'''<br/>ffwiki.cap(6, 5, 7) -> '''{{#invoke:WikiFunctions|lua|ffwiki|cap|6|5|7}}'''
 
|Returns number raised at least to minimum or lowered at least to maximum.
 
|-
 
|class="code"|{{A|ffwiki.tounderscore|.tounderscore}}
 
|<code>string</code>
 
|ffwiki.tounderscore("Final Fantasy Wiki") -> '''{{#invoke:WikiFunctions|lua|ffwiki|tounderscore|"Final Fantasy Wiki"}}'''
 
|Returns string with spaces replaced for underscores. Used to make page names URL accessible.
 
|-
 
|class="code"|{{A|ffwiki.towikitable|.towikitable}}
 
|<code>table</code><br/><code>class</code>
 
|
 
|Idk, borked.
 
|-
 
|class="code"|{{A|ffwiki.ifnotblank|.ifnotblank}}
 
|<code>value</code>
 
|ffwiki.ifnotblank() -> '''{{#invoke:WikiFunctions|lua|ffwiki|ifnotblank}}'''<br/>ffwiki.ifnotblank(nil) -> '''{{#invoke:WikiFunctions|lua|ffwiki|ifnotblank|nil}}'''<br/>ffwiki.ifnotblank("") -> '''{{#invoke:WikiFunctions|lua|ffwiki|ifnotblank|""}}'''<br/>ffwiki.ifnotblank("a") -> '''{{#invoke:WikiFunctions|lua|ffwiki|ifnotblank|"a"}}'''
 
|Returns boolean value for input containing data (not nil or empty string).
 
|-
 
|class="code"|{{A|ffwiki.reargs|.reargs}}
 
|<code>Frame.args</code>
 
| -
 
|Returns standard table of data mimicking <code>frame.args</code>. Necessary to edit data and get length.
 
|-
 
|class="code"|{{A|ffwiki.emptystring|.emptystring}}
 
|<code>table</code>
 
|ffwiki.emptystring({"A", " ", "B", ""} -> {{#invoke:WikiFunctions|lua|ffwiki|emptystring|{"A", " ", "B", ""} }}
 
|Returns standard table of data mimicking input table albeit with blank or whitespace inputs removed. Also returns table. Designed to remove blank properties from <code>frame.args</code>.
 
|-
 
|class="code"|{{A|ffwiki.luaparam|.luaparam}}
 
|<code>table</code>
 
|ffwiki.luaparam({"5", "\"N\"", "true", "{'A', 'B'}", nil}) -> table({ 5, "N", true, { "A", "B" }, 6 = "a" })
 
|Converts frame inputs from wikitext strings to values as if processed by Lua, e.g. inputs surrounded by quotation marks are strings. Does not clone table, so readonly tables like Frame.args will have to be converted first.
 
|-
 
|class="code"|{{A|ffwiki.unescapewikitext|.unescapewikitext}}
 
|<code>string</code><br/><code>pipe</code> - string pipe escape (<code><nowiki>|</nowiki></code>) (default: "<code>\</code>")<br/><code>tempin</code> string template open (<code>{<nowiki/>{)</code>) (default: "<code>{@</code>")<br/><code>tempout</code> string template out (<code>}}</code>) (default: "<code>@}</code>"<br/><code>equals</code> - string equals string (<code>=</code>) (default: "<code>~</code>")
 
|ffwiki.unescapwikitext("{@tl\\1~A@}") -> '''{{#tag:nowiki|{{#invoke:WikiFunctions|lua|ffwiki|unescapewikitext|"<tl!1?A>"|"!"|"<"|">"|"?"}}}}<!--i'm lying because it script errors for no reason if i do how it is supposed to. works fine in Lua though-->'''<br/>ffwiki.unescapewikitext("<tl!1?A>", "!", "<", ">", "?") -> '''{{#tag:nowiki|{{#invoke:WikiFunctions|lua|ffwiki|unescapewikitext|"<tl!1?A>"|"!"|"<"|">"|"?"}}}}'''
 
|Returns input string with escape substrings replaced with unescaped substrings. If parameters are false then nothing unescapes to that string.
 
|-
 
|class="code"|{{A|ffwiki.type|.type}}
 
|<code>value</code>
 
|ffwiki.type("4") -> '''{{#invoke:WikiFunctions|lua|ffwiki|type|"4"}}'''<br/>ffwiki.type(array.new()) -> '''array'''
 
|Returns string name of type of object, like global [[#_G.type|<code>type</code>]]. Unlike global <code>type</code>, returns [[#.__type|<code>__type</code>]] metaproperty (or [[#__type|<code>__type</code>]] metamethod if the value is a function).
 
|-
 
|class="code"|{{A|ffwiki.expandTemplate|.expandTemplate}}
 
|<code>table{title = string, args = table{}}</code><br/><br/><code>title</code><br/><code>args - table{}</code><br/><br/><code>title</code><br/><code>args[]</code>
 
|ffwiki.expandTemplate({title = "tl", args = {"A", "expandTemplate"}) -> {{#invoke:WikiFunctions|lua|ffwiki|expandTemplate|{ title {{=}} "tl", args {{=}} {"A", "expandTemplate"} } }}<br/><br/>ffwiki.expandTemplate("tl", {"A", "expandTemplate"}) -> {{#invoke:WikiFunctions|lua|ffwiki|expandTemplate|"tl"|{"A", "expandTemplate"} }}<br/><br/>ffwiki.expandTemplate("tl", "A", "expandTemplate") -> {{#invoke:WikiFunctions|lua|ffwiki|expandTemplate|"tl"|"A"|"expandTemplate"}}
 
|Returns code of template from template name and arguments (parameters). Based on the [[#Frame:expandTemplate|<code>:expandTemplate</code>]] Frame method designed to be (abstractly) independent of a frame.
 
|}
 
 
====<code>switch</code>====
 
Lua does not have a native <code>switch</code>, and so one must get creative to find out equivalents of doing it. For simple switches where values are assigned in each case of the div, the values can be placed in a table where the keys match the cases, and the match can be tested in a loop. If we are still assigning then we might put a function with IF logic inside that takes a short-named parameter that takes the test value so it is not quite the same as typing in a variable name multiple times. If we're not assigning the value then IF, ELSEIF, ELSE may be used but then we are typing in the variable multiple times which feels unnecessary.
 
 
The <code>switch</code> function in this library aims to be a more suitable fix. It attempts to mimic the general idea of the SWITCH structure in other languages.
 
 
:<source lang="lua" class="inline">ffwiki.switch( </source> ''test''<source lang="lua" class="inline"> , </source> [ ''matches''<source lang="lua" class="inline"> , </source> ''function'' ] <source lang="lua" class="inline"> , </source>''else''<source lang="lua" class="inline">)</source>
 
 
The above syntax intends to imply that an infinite amount of matches and function pairs can be used, and the else function comes after. The else function is optional. <code>matches</code> is always an auto-indexed table of values, even if it only contains one value.
 
 
Tests <code>test</code> value for equivalent inside tables and executes following function if match is found (only for the first match).
 
:<source lang="lua" class="inline">ffwiki.switch("A", { "B", "C" }, function() return "1" end, { "A" }, function() return "2" end) --> 2</source>
 
:<source lang="lua" class="inline">ffwiki.switch("A", { "B", "C" }, function() return "1" end, { "B" }, function() return "2" end) --> nil</source>
 
 
An empty table always counts as a match.
 
:<source lang="lua" class="inline">ffwiki.switch("A", { "B", "C" }, function() return "1" end, {}, function() return "2" end) --> 2</source>
 
 
If the last function in a table is not prefixed by a match table then it is the assumed else function and runs if no matches have been found.
 
:<source lang="lua" class="inline">ffwiki.switch("A", { "B", "C" }, function() return "1" end, function() return "2" end) --> 2</source>
 
 
===[[Module:Tabber]]===
 
Module for utilizing tabber elements simply without need of specific knowledge of how it works. It creates [[#Tabber|Tabber]] and [[#Tab|Tab]] objects.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|class="code"|{{A|tabber.create|.create}}
 
|<code>title</code> (optional)<br/><code>tabs[]</code> - Tabs to append on creation
 
|{{Doclua|tabber.create()}}
 
|}
 
 
 
===[[Module:Expr]]===
 
Module for running calculations from strings. This is primarily for the benefit of passing expressions from {{tl|#invoke}} functions.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Function
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|calc
 
|<code>expression</code>
 
|expr.calc("2+2") → '''{{#invoke:WikiFunctions|lua|expr|calc|"2+2"}}'''
 
|Returns expression evaluated.
 
|}
 
 
==Classes==
 
===Array===
 
The <code>Array</code> class allows the execution of relevant functions from the object. It is a part of [[#Module:Array|Module:Array]], where its functions are covered. A new array is created with <source lang="lua" class="inline">array.new()</source>, and an optional parameter is a table which is converted to an array.
 
 
===Frame===
 
The <code>Frame</code> class holds information sent by a template (including uses of {{tl|#invoke}}). Frame objects cannot be created in Lua itself, and therefore debugging them can be a nightmare. They are instead created when a function is called from wikitext. The frame is the single parameter of the template, though multiple frames can still exist in each call due to Frame objects having parents, and having a method to call them.
 
 
;{{A|Frame.args|.args}}
 
The <code>.args</code> property is a readonly table of the arguments submitted. Parameter names map to property names much the same was as creating a table in Lua would, unnamed parameters become auto-indexed properties.
 
 
While the reference to the table can be overwritten, this means nothing. Methods that reference a frame's arguments do not use <code>args</code> as their source, so the originally submitted arguments will still be used.
 
 
Due to its readonly state the [[#ffwiki.reargs|ffwiki.reargs]] function exists to clone the table into something editable.
 
 
All values stored are strings. The [[#ffwiki.luaparam|ffwiki.luaparam]] function exists to convert values from string to different Lua formats in a previously converted table.
 
 
Named arguments will have leading and trailing whitespace removed from both the name and the value before they are passed to Lua, whereas unnamed arguments will not have whitespace stripped. Empty or whitespace parameters can be removed from a table with [[#ffwiki.emptystring|ffwiki.emptystring]].
 
 
;{{A|Frame:getParent|:getParent}}
 
The <code>:getParent</code> method gets the current frame's parent frame. The parent frame is the one that called it, i.e. the {{tl|#invoke}} is the original frame, but if that {{tl|#invoke}} is in a template and that template is transcluded, then the parameters submitted to that template is the parent frame. If that template is transcluded in another template, then the parent of the original parent's parent is the parameters submitted to the second template, etc., e.g.:
 
:frame: {{tl|#invoke:Talk|main}}; frame.getParent(): {{tl|Talk}}; frame:getParent():getParent(): <code>&#123;{User:{{USERNAME|[username]}}/Talk}}</code>
 
 
If a frame has no parent, a Frame object is still returned, it is just one with an empty <code>args</code> table. Therefore checking if mandatory parameters exist in a parent's <code>args</code> table is one way to decide whether to use parameters found on a parent's frame to allow a user to {{tl|#invoke}} directly or use a template (although the template is typically the preferred method as it is more likely to remain, unlike the location of functions).
 
 
;{{A|Frame:expandTemplate|:expandTemplate}}
 
The <code>:expandTemplate</code> method takes the name and arguments of a template and generates its output. Template syntax returned from Lua will not be resolved otherwise.
 
 
The reason why such a useful function is found on the Frame object (and thus requires passing it to functions if they are not called by an {{tl|#invoke}} directly) is that parameters can be written in wikitext style and be replaced in the output with the value from its initial arguments table (Note: replacing the <code>args</code> table does not change the arguments that will be replaced).
 
 
<code>expandTemplate</code> takes a single parameter, a table with the properties <code>title</code> and <code>args</code>. The <code>args</code> property is a table itself, and containers the template's parameters in a Lua table.
 
 
:<code>frame:expandTemplate{ title = ''title'', args = ''table'' }</code>
 
 
For example:
 
:<source lang="lua" class="inline">frame:expandTemplate{ title = "tag", args = { "div", class = "aclass", "content" } }</source>
 
 
Will result in: {{tag|div|class=aclass|content}}, the same as {{tl|tag|div|class=aclass|content}}.
 
 
The <code>title</code> parameter functions the same as when transcluding templates, in that not specifying a namespace results in the template being taken from templatespace, while specifying one has it be taken from that namespace.
 
 
;{{A|Frame:preprocess|:preprocess}}
 
The <code>:preprocess</code> method evaluates a string as wikitext and returns the code within Lua.
 
 
:<code>frame:preprocess( ''string'' )</code>
 
 
Since templates can be created with [[#Frame:expandTemplate|<code>:expandTemplate</code>]], parameters can be taken directly from [[#Frame.args|<code>.args</code>]], and most other wikitext can be resolved when returned to the page, this may seem useless.
 
 
However its actual use is similar in vein to [[#Html:cssText|<code>Html:cssText</code>]]. For that, it does not care what it contains, it need only be CSS styles. <code>preprocess</code> is to wikitext as that is to CSS. Although there is of course one small difference: CSS can be submitted as a string fine, but wikitext cannot without being resolved before getting to the module.
 
 
At least, not without escaping. The [[#ffwiki.unescapewikitext|<code>ffwiki.unescapewikitext</code>]] function exists for this purpose. Wikitext can be submitted escaped so templates, pipes, and equals signs are not evaluated before they are submitted to Lua. Escaping via {{tag|nowiki}} tags means evaluating is not possible to Lua, the input string will always be the same as input.
 
 
An example use:
 
 
:<code>frame:preprocess("<nowiki>'''Bold''', ''italic'', {{tag|a}}, {{{1}}}</nowiki>")</code> (where <code>frame.args == { "A" }</code>)
 
 
Would output: '''Bold''', ''italic'', {{tag|a}}, A
 
 
===Language===
 
Part of the <code>mw</code> library and most associated with the <code>[[#mw.language|mw.language]] functions, the <code>Language</code> class holds a MediaWiki language and provides methods based on conventions in those languages. This includes number formatting and string formatting.
 
 
The class provides a single property, <code>code</code>, which is the language identifier.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Method
 
!style="width:20%"|Parameters
 
!style="width:20%"|Example
 
!Description
 
|-
 
|<code>getCode</code>
 
| -
 
|{code:"en"}:getCode() -> "en"
 
|Returns the object's code prefix. Identical to the value returned by the <code>code</code> property.
 
|-
 
|<code>lc</code>
 
|<code>string</code>
 
|{code:"en"}:lc("DoG") -> "dog"
 
|Returns string converted to lowercase accounting for special language rules.
 
|-
 
|<code>uc</code>
 
|<code>string</code>
 
|{code:"en"}:uc("cog") -> "COG"
 
|Returns string converted to uppercase accounting for special language rules.
 
|-
 
|<code>lcfirst</code>
 
|<code>string</code>
 
|{code:"en"}:lcfirst("CoW") -> "coW"
 
|Returns string with first character converted to lowercase accounting for special language rules.
 
|-
 
|<code>ucfirst</code>
 
|<code>string</code>
 
|{code:"en"}:ucfirst("doG") -> "DoG"
 
|Returns string with first character converted to uppercase accounting for special language rules.
 
|-
 
|<code>caseFold</code>
 
|
 
|{code:"en"}:caseFold("dOg") -> "DOG"
 
|Returns converted string to format suitable for case insensitive comparison.
 
|-
 
|<code>isRTL</code>
 
| -
 
|{code:"en"}:isRTL() -> false
 
|Returns boolean for language read left to right.
 
|-
 
|<code>{{A|Language:plural|plural}}</code>
 
|<code>number</code> - <code>number</code> of items<br/><code>singular</code> - string</br><code>plural</code> - string
 
|{code:"en"}:plural(1, "cow", "cows") -> "cow"<br/>{code:"en"}:plural(2, "cow", "cows") -> "cows"
 
|Returns <code>singular</code> or <code>plural</code> depending on if the <code>number</code> of things would require singular or plural in the language.
 
|-
 
|<code>{{A|Language:gender|gender}}</code>
 
|<code>string</code><br/><code>male</code> - string<br/><code>female - string<br/><code>unknown</code> - string (default: <code>male</code>)
 
|{code:"en"}:gender("female","dog", "doge")) -> "doge<br/>{code:"en"}:gender("","dog", "doge")) -> "dog"<br/>{code:"en"}:gender("","dog", "doge", "doeg")) -> "doeg"
 
|Returns <code>male</code> string if input is <code>"male"</code>, <code>female</code> if <code>"female"</code>, and <code>other</code> in all other circumstances. Supposedly you can test by username too.
 
|-
 
|<code>{{A|Language:formatNum|formatNum}}</code>
 
|<code>number</code>
 
|{code:"en"}:formatNum(24525.525) -> "24,525.525"
 
|Returns <code>number</code> as string formatted appropriately for language.
 
|-
 
|<code>{{A|Language:parseFormattedNumber|parseFormattedNumber}}</code>
 
|<code>string</code> - <code>string</code> number representation
 
|{code:"en"}:parseFormattedNumber("24,525.525") -> 24525.525
 
|Returns <code>number</code> from string using language's number presentation format as basis.
 
|-
 
|<code>{{A|Language:formatDate|formatDate}}</code>
 
|<code>format</code> - <code>string</code><br/><code>date</code> - <code>string</code> (default: current datetime)
 
|{code:"en"}:formatDate("Y/m/d H:i:s", "201306151627") -> "2013/06/15 16:27:00<br/>{code:"en"}:formatDate("Y/m/d H:i:s") -> (formatted current UTC date)
 
|Returns <code>date</code> as string following <code>format</code>.
 
|}
 
 
===Html===
 
The Html class is a table that contains information about a HTML element. Using the value of an object as a string will print the valid HTML syntax of the element given the stored information.
 
 
The properties are not meant to be edited themselves, instead the object's methods are to be used to modify the values. However to give an idea of how the class works, this is how the HTML objects are stored:{{foot|An index of "[0]" indicates it is a format for auto-indexed properties with potentially infinite parameters. Where there are duplicate keys it means there are multiple potential formats.}}
 
 
<source lang="lua" class="block">
 
{
 
styles = {
 
[0] = {
 
name = <property name>,
 
val = <value>
 
},
 
[0] = <css string>
 
},
 
attributes = {
 
[0] = {
 
name = <attribute name>,
 
val = <value>
 
}
 
},
 
selfClosing = <boolean>,
 
nodes = {
 
[0] = <wikitext string>,
 
[0] = <HtmlObject>
 
},
 
tagName = <tag name>
 
}
 
</source>
 
 
While classes are handled in <code>attributes</code>, styles are not. This is noteworthy due to the functionality of the [[#Html:getAttr|getAttr]] method.
 
 
;{{A|Html:attr|:attr}}
 
The <code>:attr</code> method assigns a string value to a string attribute name and assigns that to the calling tag. The calling tag is returned.
 
 
It is not possible to add an attribute name without value (which would be valid for boolean attributes like <code>disabled</code>), though simply assigning a blank value in these cases is sufficient.
 
 
There are two formats for this method:
 
 
:<source lang="lua" class="inline">HtmlObj:attr( </source><code>''attributename''</code><source lang="lua" class="inline"> , </source><code>''value'</code>'<source lang="lua" class="inline"> )</source>
 
 
<code>attributename</code> specifies an attribute like <code>id</code>, and the <code>value</code> is the assigned value.
 
 
:<source lang="lua" class="inline">HtmlObj:attr( </source><code>''attributetable''</code><source lang="lua" class="inline">)</source>
 
 
The format of the table would be:
 
:<source lang="lua" class="inline">{ </source><code>''attributename''</code><source lang="lua" class="inline">=</source><code>''value''</code><source lang="lua" class="inline"> }</source>
 
 
This is similar to the first method, however using a table allows multiple attributes to be assigned at once.
 
 
Examples:
 
:<source lang="lua" class="inline">mw.html.create("div"):attr("id", "anid")</source> -> '''&lt;div id="anid"></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):attr("id", "anid"):attr("id", "newid")</source> -> '''&lt;div id="newid"></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):attr("id", "anid"):attr("title", "atitle")</source> -> '''&lt;div id="newid" title="atitle"></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):attr({ id = "anid", title = "atitle" })</source> -> '''&lt;div id="anid" title="atitle"></div>'''
 
 
;{{A|Html:addClass|:addClass}}
 
The <code>:addClass</code> method adds a class name to the <code>class</code> attribute to the calling element. The calling element is returned. In more complex terms, the method checks whether the tag has a class attribute, and if it does not it adds one with the specified value. If one does exist then it just adds the value onto the end (with a space). This means that multiple classes can be added in one <code>:addClass</code> call if they are space-separated.
 
 
Classes can also be added through [[#Html:attr|:attr]], however using this functions allows the value held by the class to be appended to rather than replaced.
 
 
The format:
 
:<source lang="lua" class="inline">HtmlObj:addClass( </source><code>''classname''</code><source lang="lua" class="inline"> )</source>
 
 
Examples:
 
:<source lang="lua" class="inline">mw.html.create("div"):addClass("one-class")</source> -> '''&lt;div class="one-class"></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):addClass("one-class"):addClass("two-class")</source> -> '''&lt;div class="one-class two-class"></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):addClass("one-class two-class")</source> -> '''&lt;div class="one-class two-class"></div>'''
 
 
;{{A|Html:css|:css}}
 
The <code>:css</code> method pairs a CSS property with a value and adds it to the calling element. The calling element is returned. It works similarly in concept to [[#Html:attr|<code>:attr</code>]] and how it pairs attributes with values. Using it for a property that does not exist will add it to the element with the given value, and using for one that does will replace the property's value.
 
 
There are two formats for this method:
 
 
:<source lang="lua" class="inline">HtmlObj:css( </source><code>''propertyname''</code><source lang="lua" class="inline"> , </source><code>''value''</code><source lang="lua" class="inline"> )</source>
 
 
<code>propertyname</code> specifies a property like <code>color</code>, and the <code>value</code> is the assigned value as a string.
 
 
:<source lang="lua" class="inline">HtmlObj:css( </source><code>''propertytable''</code><source lang="lua" class="inline">)</source>
 
 
The format of the table would be:
 
:<source lang="lua" class="inline">{ </source><code>''propertyname''</code><source lang="lua" class="inline">=</source><code>''value''</code><source lang="lua" class="inline"> }</source>
 
 
This is similar to the first method, however using a table allows multiple properties to be assigned at once.
 
 
Examples:
 
:<source lang="lua" class="inline">mw.html.create("div"):css("text-align", "left")</source> -> '''&lt;div style="text-align:left;"></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):css("text-align", "left"):css("text-align", "right")</source> -> '''&lt;div style="text-align:right;"></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):css("text-align", "left"):css("color", "red")</source> -> '''&lt;div style="text-align:right;color:red"></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):css({ ["text-align"] = "left", color = "red"})</source> -> '''&lt;div style="text-align:right;color:red"></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):css("text-align", "left"):css("color", "red"):attr("style", "margin:0")</source> -> '''&lt;div style="margin:0;"></div>'''
 
 
;{{A|Html:cssText|:cssText}}
 
The <code>:cssText</code> method adds text to the <code>style</code> property of the calling element. The calling element is returned. <code>:cssText</code> is designed to work similarly to [[#Html:css|<code>:css</code>]], however the reason it is not just another overload of that method is that it handles styles differently. <code>:css</code> logs a property's name and value, while <code>:cssText</code> is a raw form and the Lua class does not distinguish. Due to this there are no checks for duplicate properties.
 
 
The format:
 
:<source lang="lua" class="inline">HtmlObj:cssText( </source><code>''css''</code><source lang="lua" class="inline"> )</source>
 
 
The input is literally what would go in a <code>style</code> parameter, though trailing semi-colons may be omitted as they are added automatically.
 
 
Examples:
 
:<source lang="lua" class="inline">mw.html.create("div"):cssText("text-align:left")</source> -> '''&lt;div style="text-align:left;"></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):cssText("text-align:left;"):css("text-align", "right")</source> -> '''&lt;div style="text-align:left;;text-align:right;"></div>'''
 
 
;{{A|Html:wikitext|:wikitext}}
 
The <code>:wikitext</code> methods adds text to the calling element's content. The calling element is returned. Any valid wikitext works, and HTML elements can be input in their raw form fine. <code>\n</code> does work as a new line character. The element is added as a node, which is also done by [[#Html:newline|:newline]], [[#Html:newline|:node]], and [[#Html:newline|:tag]].
 
 
The format:
 
:<source lang="lua" class="inline">HtmlObj:wikitext( </source><code>''wikitext''</code><source lang="lua" class="inline"> )</source>
 
 
Example:
 
:<source lang="lua" class="inline">mw.html.create("div"):wikitext("Hello"):wikitext(" world")</source> -> '''&lt;div>Hello world</div>'''
 
 
;{{A|Html:newline|:newline}}
 
The <code>:newline</code> method represents a new line wikitext, and adds one to the end of the content of the calling element. The calling element is returned. Has the same effect as using <code>\n</code> inside [[#Html:wikitext|:wikitext]].
 
 
The format:
 
:<source lang="lua" class="inline">HtmlObj:newline()</source>
 
 
Example:
 
:<source lang="lua" class="inline">mw.html.create("div"):wikitext("A"):newline():wikitext("B")</source> -> '''&lt;div>A<br/>B</div>'''
 
 
;{{A|Html:node|:node}}
 
The <code>:node</code> method appends a Html object to the calling element's content. The calling element is returned. The main benefit of using this is for pre-created Html objects, while [[#Html:tag|<code>:tag</code>]] can be used for ones created on the spot. With that said, <code>:node</code> may be seen as easier to use in object building chains as the building of the sub-element occurs in the brackets of a method rather than in sequence which may be confusing, especially without whitespace clarity.
 
 
The format:
 
:<source lang="lua" class="inline">HtmlObj:node( </source><code>''HtmlObj''</code><source lang="lua" class="inline"> )</source>
 
 
Example:
 
:<source lang="lua" class="inline">mw.html.create("div"):wikitext("A"):node(mw.html.create("hr")):wikitext("B")</source> -> '''&lt;div>A&lt;hr />B</div>'''
 
 
:<source lang="lua" class="inline">x = mw.html.create("br") mw.html.create("div"):wikitext("A"):node(x):wikitext("B")</source> -> '''&lt;div>A&lt;br />B</div>'''
 
 
{{A|Html:tag|:tag}}
 
The <code>:tag</code> methods appends a new instance of a Html object to the calling element's content. Unlike every other method, this method does not return the calling element, instead it returns the Html object created. Its parameters are identical to those of the class's constructor, [[#mw.html.create|<code>mw.html.create</code>]].
 
 
:<source lang="lua" class="inline">HtmlObj:tag( </source> <code>''tag''</code> <source lang="lua" class="inline">, </source><code>''args''</code><source lang="lua" class="inline"> )</source>
 
 
Where <code>args</code> is optional, and is a table that contain the property <code>selfClosing</code> which when set to <code>true</code> makes tags that are not typically self-closing self-close.
 
 
:<source lang="lua" class="inline">mw.html.create("div"):wikitext("A"):tag("div"):wikitext("B")</source> -> '''&lt;div>B</div>'''
 
 
Relevant is the [[#Html:done|<code>:done</code>]] method.
 
 
;{{A|Html:done|:done}}
 
The <code>:done</code> method returns the Html object creator of an element created through the <code>:tag</code> method. Ergo, it returns control to the element that called the <code>:tag</code> element.
 
 
The format:
 
:<source lang="lua" class="inline">HtmlObj:done()</source>
 
 
Examples:
 
:<source lang="lua" class="inline">mw.html.create("div"):tag("div"):wikitext("A"):done()</source> -> '''&lt;div>&lt;div>A</div></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):tag("div"):done():wikitext("A")</source> -> '''&lt;div>&lt;div></div>A</div>'''
 
 
;{{A|Html:allDone|:allDone}}
 
The <code>:allDone</code> method works the same as <code>:done</code> method but acts recursively to find the original element being created.
 
 
The format:
 
:<source lang="lua" class="inline">HtmlObj:allDone()</source>
 
 
For reference, here is what is returned in a chain of four {{tag|div}} tags:
 
 
:<source lang="lua" class="inline">mw.html.create("div"):tag("div"):tag("div"):tag("div")</source> -> '''&lt;div></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):tag("div"):tag("div"):tag("div"):done()</source> -> '''&lt;div>&lt;div></div></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):tag("div"):tag("div"):tag("div"):done():done()</source> -> '''&lt;div>&lt;div>&lt;div></div></div></div>'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):tag("div"):tag("div"):tag("div"):allDone()</source> -> '''&lt;div>&lt;div>&lt;div>&lt;div></div></div></div></div>'''
 
 
;{{A|Html:getAttr|:getAttr}}
 
Unlike the other methods, the <code>:getAttr</code> method is not designed to be used on the chain of creation (although it still can be). The method returns the value of the specified attribute.
 
 
One thing to note about <code>:getAttr</code> is its inability to return the value of the <code>style</code> property. The <code>style</code> attribute is handled separately from other attributes, though what makes this peculiar is that [[#Html:attr|<code>:attr</code>]] distinguishes uses of the <code>style</code> property and treats it differently while this does not.
 
 
 
Format:
 
:<source lang="lua" class="inline">HtmlObj:getAttr( </source><code>''attributename''</code><source lang="lua" class="inline"> )</source>
 
 
Examples:
 
 
:<source lang="lua" class="inline">mw.html.create("div"):getAttr("id")</source> -> '''nil'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):attr("id", "anid"):getAttr("id")</source> -> '''anid'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):attr("style", "color:red"):getAttr("style")</source> -> '''nil'''
 
 
:<source lang="lua" class="inline">mw.html.create("div"):addClass("cow dog"):getAttr("class")</source> -> '''cow dog'''
 
 
===Namespace===
 
Namespace objects are returned by some functions in [[#mw.site.stats|<code/>mw.site</code>]]. The easiest way to return the information for a desired namespace is to use the <code>mw.site.namespaces</code> object, either by referencing the namespace number like <code>mw.site.namespaces[4]</code>, or referencing the namespace name, like <code>mw.site.namespaces.Project</code>.
 
 
The values of the object are from a query to the database and therefore the object is not intended to be manipulated. There are no functions.
 
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Property
 
!style="width:20%"|Output
 
!Description
 
|-
 
|class="code"|{{A|Namespace.id|.id}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|id}}<br/>{{ns:828}}: {{#invoke:WikiFunctions|lua|mw|site|namespaces|828|id}}
 
|Returns ID of namespace.
 
|-
 
|class="code"|{{A|Namespace.name|.name}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|name}}<br/>{{ns:4}}: {{#invoke:WikiFunctions|lua|mw|site|namespaces|4|name}}
 
|Returns name of namespace.
 
|-
 
|class="code"|{{A|Namespace.canonicalName|.canonicalName}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|canonicalName}}<br/>{{ns:4}}: {{#invoke:WikiFunctions|lua|mw|site|namespaces|4|canonicalName}}
 
|Returns canonical name of namespace.
 
|-
 
|class="code"|{{A|Namespace.displayName|.displayName}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|displayName}}
 
|Returns display name of namespace, only on mainspace.
 
|-
 
|class="code"|{{A|Namespace.aliases|.aliases}}
 
|(main): {{doclua|mw.site.namespaces[0].aliases}}<br/>{{ns:6}}: {{doclua|mw.site.namespaces[6].aliases}}
 
|Returns alternate names for namespaces as auto-indexed table. "Project" does not count.
 
|-
 
|class="code"|{{A|Namespace.isContent|.isContent}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|isContent}}<br/>{{ns:2}}: {{#invoke:WikiFunctions|lua|mw|site|namespaces|2|isContent}}
 
|Returns boolean for if content namespace.
 
|-
 
|class="code"|{{A|Namespace.isSubject|.isSubject}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|isSubject}}<br/>{{ns:7}}: {{#invoke:WikiFunctions|lua|mw|site|namespaces|7|isSubject}}
 
|Returns boolean for if subject namespace.
 
|-
 
|class="code"|{{A|Namespace.isTalk|.isTalk}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|isTalk}}<br/>{{ns:7}}: {{#invoke:WikiFunctions|lua|mw|site|namespaces|7|isTalk}}
 
|Returns boolean for if talk namespace.
 
|-
 
|class="code"|{{A|Namespace.isMovable|.isMovable}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|isMovable}}<br/>{{ns:-1}}: {{#invoke:WikiFunctions|lua|mw|site|namespaces|-1|isMovable}}
 
|Returns boolean for if pages within the namespace can be moved.
 
|-
 
|class="code"|{{A|Namespace.isCapitalized|.isCapitalized}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|isCapitalized}}<br/>{{ns:10}}: {{#invoke:WikiFunctions|lua|mw|site|namespaces|10|isCapitalized}}
 
|Returns boolean for if pages within the namespace have their first letter capitalized.
 
|-
 
|class="code"|{{A|Namespace.isIncludable|.isIncludable}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|isIncludable}}<br/>{{ns:-1}}: {{#invoke:WikiFunctions|lua|mw|site|namespaces|-1|isIncludable}}
 
|Returns boolean for if pages within the namespace can be transcluded.
 
|-
 
|class="code"|{{A|Namespace.hasSubpages|.hasSubpages}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|hasSubpages}}<br/>{{ns:6}}: {{#invoke:WikiFunctions|lua|mw|site|namespaces|6|hasSubpages}}
 
|Returns boolean for if pages recognize subpages.
 
|-
 
|class="code"|{{A|Namespace.hasGenderDistinction|.hasGenderDistinction}}
 
|(main): {{#invoke:WikiFunctions|lua|mw|site|namespaces|0|hasGenderDistinction}}
 
|Returns boolean for if the namespace has different aliases for different genders.
 
|-
 
|class="code"|{{A|Namespace.subject|.subject}}
 
|(main): mw.site.namespace[{{#invoke:WikiFunctions|lua|mw|site|namespaces|1|subject|id}}]<br/>{{ns:1}}: mw.site.namespace[{{#invoke:WikiFunctions|lua|mw|site|namespaces|1|subject|id}}]
 
|Returns subject namespace of namespace as Namespace object.
 
|-
 
|class="code"|{{A|Namespace.talk|.talk}}
 
|(main): mw.site.namespace[{{#invoke:WikiFunctions|lua|mw|site|namespaces|1|talk|id}}]<br/>{{ns:1}}: mw.site.namespace[{{#invoke:WikiFunctions|lua|mw|site|namespaces|1|talk|id}}]
 
|Returns talk namespace of namespace as Namespace object.
 
|}
 
 
===Title===
 
There are two types of Title objects, pages on the local wiki and pages that are not. Pages that are not can be non-existent pages, but they can also be pages on other wikis for example. Various information cannot be got from these pages like their ID or their contents, though analysis of the given title such as interwiki prefix can still be done.
 
 
The below examples make reference to the following IDs:
 
*1: [[:File:Wiki.png]]
 
*3: [[Final Fantasy Wiki]]
 
*12: [[Project:About]]
 
 
====Properties====
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Property
 
!style="width:20%"|Output
 
!Description
 
|-
 
|class="code"|{{A|Title.id|.id}}
 
|{{Doclua|mw.title.new("Final Fantasy Wiki").id}}
 
|-
 
|class="code"|{{A|Title.interwiki|.interwiki}}
 
|{{Doclua|mw.title.new("de:Final Fantasy Wiki").interwiki}}<br/>{{Doclua|mw.title.new("Final Fantasy Wiki").interwiki}}
 
|-
 
|class="code"|{{A|Title.namespace|.namespace}}
 
|{{Doclua|mw.title.new("Final Fantasy Wiki").namespace}}<br/>{{Doclua|mw.title.new("DNE", "Talk").namespace}}
 
|-
 
|class="code"|{{A|Title.nsText|.nsText}}
 
|{{Doclua|mw.title.new("Final Fantasy Wiki").nsText}}<br/>{{Doclua|mw.title.new("DNE", 1).nsText}}
 
|-
 
|class="code"|{{A|Title.subjectNsText|.subjectNsText}}
 
|{{Doclua|mw.title.new("Project:About").subjectNsText}}<br/>{{Doclua|mw.title.new("DNE", 5).subjectNsText}}
 
|-
 
|class="code"|{{A|Title.text|.text}}
 
|{{Doclua|mw.title.new("de:Talk:Final Fantasy Wiki").text}}<br/>{{Doclua|mw.title.new(12).text}}
 
|-
 
|class="code"|{{A|Title.prefixedText|.prefixedText}}
 
|{{Doclua|mw.title.new("de:Talk:Final Fantasy Wiki").prefixedText}}<br/>{{Doclua|mw.title.new(12).prefixedText}}
 
|-
 
|class="code"|{{A|Title.baseText|.baseText}}
 
|{{Doclua|mw.title.new("Talk:Final Fantasy VII").baseText}}<br/>{{Doclua|mw.title.new("Final Fantasy VII/Translations").baseText}}
 
|-
 
|class="code"|{{A|Title.subpageText|.subpageText}}
 
|{{Doclua|mw.title.new("Talk:Final Fantasy VII").subpageText}}<br/>{{Doclua|mw.title.new("Final Fantasy VII/Translations").subpageText}}
 
|-
 
|class="code"|{{A|Title.canTalk|.canTalk}}
 
|{{Doclua|mw.title.new("Talk:Final Fantasy VII").canTalk}}<br/>{{Doclua|mw.title.new("DNE").canTalk}}<br/>{{Doclua|mw.title.new("Special:AllPages").canTalk}}
 
|-
 
|class="code"|{{A|Title.fileExists|.fileExists}}
 
|{{Doclua|mw.title.new("File:DNE.fmt").fileExists}}<br/>{{Doclua|mw.title.new(1).fileExists}}<br/>{{Doclua|mw.title.new(3).fileExists}}
 
|-
 
|class="code"|{{A|Title.isContentPage|.isContentPage}}
 
|{{Doclua|mw.title.new("DNE").isContentPage}}<br/>{{Doclua|mw.title.new(3).isContentPage}}<br/>{{Doclua|mw.title.new(1).isContentPage}}
 
|-
 
|class="code"|{{A|Title.isExternal|.isExternal}}
 
|{{Doclua|mw.title.new("de:DNE").isExternal}}<br/>{{Doclua|mw.title.new(3).isExternal}}<br/>{{Doclua|mw.title.new(1).isExternal}}
 
|-
 
|class="code"|{{A|Title.isLocal|.isLocal}}
 
|{{Doclua|mw.title.new("de:Final Fantasy Wiki").isLocal}}<br/>{{Doclua|mw.title.new("wikipedia:Final Fantasy").isLocal}}<br/>{{Doclua|mw.title.new("w:c:square:finalfantasy").isLocal}}<br/>{{Doclua|mw.title.new("de:DNE").isLocal}}<br/>{{Doclua|mw.title.new(3).isLocal}}<br/>{{Doclua|mw.title.new(1).isLocal}}
 
|Title of a page not on "wikia.com".
 
|-
 
|class="code"|{{A|Title.isRedirect|.isRedirect}}
 
|{{Doclua|mw.title.new("DNE").isRedirect}}<br/>{{Doclua|mw.title.new(3).isRedirect}}<br/>{{Doclua|mw.title.new("Main Page").isRedirect}}
 
|}
 
 
====Methods====
 
{|class="full-width table" style="font-size:10px; text-align:left"
 
!style="width:15%"|Method
 
!style="width:20%"|Inputs
 
!style="width:20%"|Output
 
!Description
 
|-
 
|class="code"|{{A|Title:fullUrl|:fullUrl}}
 
|<code>query</code><br/><code>proto</code> - (<code>"http"</code>, <code>"https"</code>, <code>"relative"</code>, <code>"canonical"</code> (default: <code>"relative"</code>))
 
|{{Doclua|mw.title.new("w:c:square:Final Fantasy"):fullUrl()}}<br/>{{Doclua|mw.title.new("wikipedia:Final Fantasy"):fullUrl()}}<br/>{{Doclua|mw.title.new("fr:Final Fantasy"):fullUrl()}}<br/>{{Doclua|mw.title.new(12):fullUrl()}}<br/>{{Doclua|mw.title.new("http://www.khwiki.com/Kingdom_Hearts_III"):fullUrl()}} --URL inputs do not work
 
|}
 
   
 
==Discussion==
 
==Discussion==
Line 2,792: Line 27:
 
{{User:Technobliterator/Talk|00:34, September 14, 2014 (UTC)|Navbox will be a lot easier than you think. A lot of it is repetition and options, both things Lua handles far better than ParserFunctions ever could. Aside from that, it's literally all HTML with CSS classes. Once we got the bigger Modules down, Navbox will be easy.
 
{{User:Technobliterator/Talk|00:34, September 14, 2014 (UTC)|Navbox will be a lot easier than you think. A lot of it is repetition and options, both things Lua handles far better than ParserFunctions ever could. Aside from that, it's literally all HTML with CSS classes. Once we got the bigger Modules down, Navbox will be easy.
   
Infoboxes; there are different kinds. Enemy ones, with the way they're handled, I'd say that'd be something along the lines of making our own /stats builder, or just our own /stats using thing. If you look at {{tl|FFVI Enemy}} , it's basically a few transclusions of {{tl|FFVI Enemy/stats}}. We can make something either that repeats that transclusion but modifies the 1-5 or snes/ps/gba/ios param based on which is being transcluded for each tab, and/or have something that builds the /stats more easily than MediaWiki and ParserFunctions. I'm imagining a weird hybrid of Navbox and our current infoboxes. Thinking about it, the Character ones wouldn't be too different, would just use different CSS classes. Should probably begin that Infobox Megathread someday...not that there's as much to discuss.
+
Infoboxes; there are different kinds. Enemy ones, with the way they're handled, I'd say that'd be something along the lines of making our own /stats builder, or just our own /stats using thing. If you look at FFVI Enemy , it's basically a few transclusions of FFVI Enemy/stats. We can make something either that repeats that transclusion but modifies the 1-5 or snes/ps/gba/ios param based on which is being transcluded for each tab, and/or have something that builds the /stats more easily than MediaWiki and ParserFunctions. I'm imagining a weird hybrid of Navbox and our current infoboxes. Thinking about it, the Character ones wouldn't be too different, would just use different CSS classes. Should probably begin that Infobox Megathread someday...not that there's as much to discuss.
   
 
Some other minor things: a module for Lbox and Mbox is easily doable. Could easily <del>metatemplate </del> Module new stuff. ParserFunctions should probably be replaced wikiwide using Intangir Bot once converted. Dunno if we want to make templates, so Template:If, or just use the module invokes.
 
Some other minor things: a module for Lbox and Mbox is easily doable. Could easily <del>metatemplate </del> Module new stuff. ParserFunctions should probably be replaced wikiwide using Intangir Bot once converted. Dunno if we want to make templates, so Template:If, or just use the module invokes.

Latest revision as of 19:24, 3 January 2020

FFWiki forum logo
Forums: Index > Rin's Travel Agency > Archive > Lua modules master thread


FFVII Cait Sith Battle

Discussion[]

The modules and their methods and properties should be documented. Help:Lua would be the consistent place for it. JBed (talk) 23:34, September 13, 2014 (UTC)

Technobliterator

Using bots to turn {{#if: to {{if| would be a bad idea. Parser functions work slightly differently to templates in that their parameters allow "=". So changing the former to the latter will break things if you try to do it without checking the outcome.

And yeah, I vote we {{#invoke}} in templates. Ergo, people who don't use Lua need never reference modules. They transclude templates which invoke modules. JBed (talk) 00:53, September 14, 2014 (UTC)

Technobliterator
FFVII Cait Sith Battle
Technobliterator
FFVII Cait Sith Battle

I'd like to see what happens when #invoke is compared to TL with regards to template include size limit. JBed (talk) 19:31, October 2, 2014 (UTC)

With templates I got 8462 and 8072 before timing out. With invoke I got 7304 twice... that doesn't sound plausible but it did happen. It being that way doesn't make sense, unless caches plays a part when being invoked from the template but not when direct invoking from a page. I might get different results if I keep trying, don't know.

We're talking 12615 before we hit template include on templates. Invoke does have template include limit, and actually we're getting 19175 uses before hitting it. Under "uses" I include both successful displays and script errors. That could mess with things, I doubt that much though.

TLs not exactly a lightweight module. I mean, it's simple but not really simple. I wonder what would happen with Talk.

I think the demo proved that processing time differences are insignificant between invoke via template vs. direct invoke; and template include size increases when invoking via templates. But the limit is just intended to be a cap to prevent bad situations, we already know from the script time outs that it's not causing a bad situation. JBed (talk) 20:13, October 2, 2014 (UTC)

Okay, I think this is almost complete now. I need to re-manage the invokables section, write an intro, and then get someone to read over the rest of the body.

Besides that there is the finishing of the documentation of mw. I also found out os was a thing few days ago. Techno, Catuse: if either of you want to document these then feel free. Although I probably have the most free time of both of you so I feel like I shouldn't really ask it of you.

I wish Scribunto gave us COOKIE access. Then we could factor in user preferences into things. Like talkbox display style: simple, forum-style, or classic FFWiki-style. That's just a simple example, there's a lot more control we'd have. JBed (talk) 07:25, October 19, 2014 (UTC)