Jump to content

Help:Modules

From Wikipedia
Lua modules on Wikipedia

Overview

[edit]

This help page provides a brief orientation to modules on test2.wikipedia, following the illustrative style shown above. Modules (often Lua-based) enable templating and complex logic within pages, enhancing maintainability and consistency across the site.

What are Modules?

[edit]

Modules are reusable code units, typically written in Lua via Scribunto. They power templates with functions and data operations that would be cumbersome in plain wikitext. Common uses include:

  • Parsing parameters and applying conditional formatting
  • Accessing page data and metadata
  • Implementing citation or infobox logic
  • Generating tables and lists programmatically

Where to Find Modules

[edit]

Using Modules in Templates

[edit]

You can invoke module functions inside templates or pages via #invoke: Script error: No such module "Example". This calls function main from Module:Example with parameters provided as named arguments.

Editing and Testing

[edit]
  • Use Module:Name/sandbox for iterative development.
  • Create tests at Module:Name/testcases with example inputs and expected outputs.
  • Employ <syntaxhighlight lang="lua"> to format code samples on documentation pages.

Best Practices

[edit]
  • Document public functions and parameters in Module:Name/doc.
  • Keep modules small and focused; split responsibilities across files where appropriate.
  • Validate inputs defensively and avoid side effects.
  • Prefer data tables under Module:Name/data for separable constants or mappings.

See also

[edit]