Lua templating/Tips and tricks

This page consists of tips and tricks on the creation/modding/debugging of lua templates.

Types of modules
There are two types of modules:
 * Modules for templates - these must contain a frame argument in one of the functions.
 * Helper modules - these modules aren't intended for inclusion on pages but to be used by other modules.

Preview
The preview button allows one to see what the module will display before it is saved. It is a good idea always to work with two pages, one with the actual module being edited and one test page that invokes the module. Rather than refreshing the test page a simple preview will save time.

Incorrectly passed arguments
These can cause problems if they contain special characters such as "=". The result will be that the module may not correctly interpret the passed arguments if they are for example part of a URL string, e.g. "  "

Debugging console

 * Debugging functions using the console - One can debug functions written in the module text area using the debug console. To do this one merely needs to call the function, e.g. mw.log(p.helloworld("howdy")).
 * Console shows two types of errors - One of the error relates to a syntax problem in the console itself, and the other relates to errors in the module text area. Simply clicking enter will show one of the two.
 * Print debug output - Output can be printed to the console using "mw.log("test")".
 * Frame - The frame is simply "nil"(empty) using the debug console, as it is created during a module being used through #invoke.

Wikimedia modules
Wikimedia modules may either work as is when they are added to wikia or may require some tweaks (if they use a different scribunto extension).