Lua templating/Getting started

This page covers some of the absolute basics for developing a simple Lua template.
== Basics ==
Before starting with Lua templates, it is important to read up and get to know how to use regular wikitext templates, and preferably read/learn about Lua in sites such as Wikibooks as well as reviewing the Lua Reference manual.
=== Workspace ===
Lua templates are stored in the Module namespace, and all work must always be saved there. For example, a module named helloworld would be stored in Module:Helloworld.
=== Creating a module ===
A module must always contain a table and a line containing a "return" for that table unless it is a meta-module (see below). 
For a module to be invoked (or used in a page), it needs to have a function. However, this function must be part of the main table (e.g. invocable):
=== Execution time ===
Lua modules used can only run for a maximum of 7 seconds. This means that modules within a page cannot take longer than 7 seconds to execute, or there will be an error.
== Copying modules to another wiki ==
Modules hosted here can be used in another wiki, but this may require steps:
# Copy the module to your wiki, e.g. Module:Links
# Copy all modules it depends on to your wiki. This is a bit complicated because Fandom uses an older Scribunto version. But these steps should help:
## Open the module page and find sections that contain text like require("text"), e.g. in module links text =="Dev:Arguments".
## Search for the module in dev.fandom or any other wiki, e.g. Module:Arguments
## Copy this Module:Arguments to your wiki
## Replace all mentions of require("Dev:") with require("module:"), e.g. require("Module:Arguments")
# Redo step two, for every time a require("") is found in copied module.
== Using input (parameters) ==
Input (or Template parameters) can be provided to a module during the invoke.)
==== Syntax ====
Once the above code is executed a table (called frame) is created containing all those inputs, and it is passed to a function, and stored in a sub-table called args (e.g. frame.args). For example, using the invoke below will make use of the module:
;Output
Explanation:
Args is a list containing all parameters, args[1] refers to the first value, e.g. john, args["name"] accesses a named parameter "name".
=== Accessing template input ===
The code in the module above, if wrapped in a wikitext template, cannot access the parameters passed to the template. Such arguments can be accessed by first retrieving the parent frame using frame:getParent(), and then accessing the sub-table frame:getParent().args:
; Template:greet
; Module:invocable
;Usage
;Output
;Usage
;Output
Example 	Parameter	Template 	Module 	Output
{{greet|john}} 	1 	{{{1}}} 	frame:getParent().args[1] 	john
{{greet|name=Spock}} 	name 	{{{name}}}}	frame:getParent().args["name"]	Spock
{{#invoke:invocable|greet|john}} 	1 	 	frame.args[1] 	john
{{#invoke:invocable|greet|name=Worf}}	name 	 	frame.args["name"] 	Worf
{{#invoke:invocable|greet|jack|jill}}	1,2 	 	frame.args[1], frame.args[2] 	Jack , Jill
== Script errors ==
Whenever a module doesn't work properly it triggers a script error in a page. A good explanation of script errors is maintained by Wikipedia.
== Advanced ==
An advantage of Lua is that it enables one to use external modules and tables that have been created by others. This reduces the need to reinvent the wheel, and more time can actually be spent creating new solutions.
=== Using other modules ===
To use libraries or modules one needs to import that library. This is done using the require method:
;Output
Note: The syntax is case sensitive so "Dev" != "dev".
==== Meta-Modules ====
These are modules that are not meant to be used in a page (e.g. {{#invoke), and don't necessarily have any functions that can be used in a page.
=== Using external tables ===
A external table can be retrieved in the same way as an external module, except that there is an extra method (mw.loadData) that loads it once per page, making it more efficient.
;Usage
;Output
=== Global modules ===
Modules stored in dev.fandom.com are called global modules. They work in a similar manner to modules stored in a wiki but can be accessed by any Lua module from another wiki (e.g. food.fandom.com). The difference lies only in the syntax (it uses "Dev" instead of "Module") used to obtain the modules:
local global_invocable = require("Dev:Invocable")
local global_Tables = mw.loadData("Dev:Tables")
== Tools ==
There are a bunch of useful tools that can help create modules:
=== Code-editor ===
The code-editor (or ace-editor) - this is the default editor that can be disabled as needed.
Ace editor in particular comes with a couple of hidden features such as keyboard shortcuts and macros.https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts
==== Keyboard shortcuts ====
A brief list of some useful shortcuts is shown below:
Windows/Linux	Mac 	Action
 	 	Copy lines down
 	 	Copy lines up
 	 	Move lines down
 	 	Move lines up
 	 	Remove to line end
 	 	Remove to linestart
 	, 	Remove word left
 	 	Remove word right
 	Split line	
Windows/Linux 	Mac	Action
 	 	Macros replay
 	 	
Macros recording	 	
=== Syntax highlighting and syntax checking ===
The interactive code editor always highlights syntax errors, and sometimes gives helpful information to fix them.
=== Debug console ===
This is a console or terminal that makes it easy to test out code.
== ==
* w:Help:Lua
* 
* 
* DEV:Lua
== References ==
Getting started