Lua templating/FAQ

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? ===
=== How do I document Lua modules? ===
Scribunto allows modules to be documented by automatically associating the module with a wikitext documentation page; by default, the "/doc" subpage of the module is used for this purpose and is transcluded above the module source code on the module page. For example, the documentation for "Module:Bananas" would be at "Module:Bananas/doc".
Note that modules cannot be directly categorized and cannot have interwiki links directly added. These could be placed on the documentation page inside <includeonly>...</includeonly> tags, where they will be applied to the module when the documentation page is transcluded onto the module page.
=== Can I access Lua modules stored in another wiki? ===
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 7 seconds on Fandom, and it also has memory limits https://www.mediawiki.org/wiki/Extension:Scribunto.
== 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? ===
Yes.
=== Are there tools for debugging a module? ===
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 ==
Category:Lua