Module:Utils/doc: Difference between revisions

From Nguhcraft Wiki
Jump to navigation Jump to search
Created page with "Utility functions to help creating modules <code>def(value, default)</code> :Returns <code>value</code> if it is not <code>nil</code> or <code>""</code>, and <code>default</code>otherwise <code>_a(arg)</code> :Extracts the argument from the common ways mediawiki passes arguments to modules: :* if <code>arg</code> is not a table, it is returned as is (Called from Lua like a function) :* if <code>arg</code> is a table and that table has a <code>args</code> field, <code>ar..."
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 8: Line 8:
:* if <code>arg</code> is a table and that table has a <code>args</code> field, <code>arg.args[1]</code> is returned (Called from MediaWiki’s <nowiki>{{#invoke:}}</nowiki> parser function)
:* if <code>arg</code> is a table and that table has a <code>args</code> field, <code>arg.args[1]</code> is returned (Called from MediaWiki’s <nowiki>{{#invoke:}}</nowiki> parser function)
:* if <code>arg</code> is a table but doesn’t contain an <code>args</code> field, <code>args[1]</code> is returned (Called with a table as an argument list<ref>Some mediawiki functions do that, idk why — Annwan</ref>)
:* if <code>arg</code> is a table but doesn’t contain an <code>args</code> field, <code>args[1]</code> is returned (Called with a table as an argument list<ref>Some mediawiki functions do that, idk why — Annwan</ref>)
<code>date(y, m, d, short = false)</code>
:Formats a date.
:If <code>short</code> is set to <code>true</code>, uses shortened months name instead of full length month names.

Latest revision as of 11:02, 23 September 2025

Utility functions to help creating modules

def(value, default)

Returns value if it is not nil or "", and defaultotherwise

_a(arg)

Extracts the argument from the common ways mediawiki passes arguments to modules:
  • if arg is not a table, it is returned as is (Called from Lua like a function)
  • if arg is a table and that table has a args field, arg.args[1] is returned (Called from MediaWiki’s {{#invoke:}} parser function)
  • if arg is a table but doesn’t contain an args field, args[1] is returned (Called with a table as an argument list[1])

date(y, m, d, short = false)

Formats a date.
If short is set to true, uses shortened months name instead of full length month names.
  1. Some mediawiki functions do that, idk why — Annwan