FANDOM


This page contains some frequent questions related to Lua templating.

General

What is Lua?

Lua is a programming language made available through Scribunto, that allows for the creation of powerful templates.

How do I convert templates to modules?

See Lua templating/Converting Wikitext templates.

How do I document Lua modules?

Unlike the template namespace, the whole module namespace is only meant for valid Lua code. So a module should be documented elsewhere, e.g. Module:mymodule -> Template:mymodule/doc or simply on the talk page.

Can I access Lua modules stored in another wiki?

Main article: Global Lua Modules

Yes, all wikis can use any module stored in dev.fandom.com, but not any other wiki.

Can I do everything with modules that I can with templates?

Yes.

Are there things that can only be done with modules?

Yes. Users can obtain the template parameters from both a transcluded page and a template, use loops, and do much more.

Are there any limits?

Yes. Lua can only execute for 10 seconds on Fandom, and it also has memory limits [1].

Programming questions

Can I pass a variable to another module on the same page?

No. Each Lua module is purposely sandboxed to prevent sharing global variables or retaining the values of another module invoked in a page.

Are there any built-in mediawiki libraries available for use?

Main article: Lua templating/Reference manual/Scribunto libraries

Yes.

Are there tools for debugging a module?

Main article: Lua templating/Debug console

Yes, there is a built-in debug console on every module page, and there are modules that facilitate debugging.

Can I access the name of the page that contains the Lua invocation?

Yes, using "frame.getParent():getTitle".

Can I access the parent page's parameters?

Yes, using "frame.getParent().args".

How do I view the Lua errors?

It depends. If the error is on a page it will get added to Category:Pages with script errors. The text containing "script error" is a clickable link that will make it possible to view the Stack trace.

Extensions

Is it compatible with extensions?

While most extensions may work, some are not fully compatible. For example, one cannot use the mw.html library to create Portable infoboxes and would need frame.preprocess.

Can Lua retrieve pages within a category?

No. As of 2016/07, Scribunto does not have this capability, and this is only available in extensions.

References

  1. https://www.mediawiki.org/wiki/Extension:Scribunto

Start a Discussion Discussions about Lua templating/FAQ

Community content is available under CC-BY-SA unless otherwise noted.

Fandom may earn an affiliate commission on sales made from links on this page.

Stream the best stories.

Fandom may earn an affiliate commission on sales made from links on this page.

Get Disney+