Help:Lua

From Team Fortress Wiki
Jump to: navigation, search

Boilerplate

Passing arguments to Lua functions

<syntaxhighlight lang="lua"> local utils = require ('Module:Utils') </syntaxhighlight> Inserting this code at the top of every module, and calling it with local args = utils.get_args(frame) at the beginning of the function, will allow you to call the function with arguments in different ways:

The first way is the standard {{#invoke:Module|function_name}} called from a template, which passes the template arguments automatically.
The second way is to allow you to pass arguments when calling the module from another module. For example, p.function({arg1 = 'foo', arg2 = 'bar'});.
The third way is to allow you to pass arguments from the template explicitly. For example, {{#invoke: Module|function| arg1 = {{{param2}}} | arg2 = {{{param1}}} }}.

Key issues

  • It is important to maintain backwards compability as templates are converted to Lua modules, to save us having to manually fix 10's or 100's of thousands of template calls. To that end it would make the most sense for existing templates to just call {{#invoke:Module|function}} which calls Module.function_name(param1, param2, ...).
  • How will users now edit certain templates with edit permissions limited to staff members? This can be split into two use cases. Those who want to edit a string or translated string and those who want to edit the module code itself. Perhaps they can request changes on the Module talk page for a staff member to review and push. Or, in the latter use case, it would be more efficient to introduce a 'module editor' user group that has edit permissions for Module pages, given to trusted and capable editors.
  • Some sort of list of code conventions and guidelines should be created. A simple document for now, that can be expanded upon as issues arise.

Resources