User:Notmyhandle/Lua notes

Lua (not LUA), which means moon in Portuguese, is a programming language. We are able to use it here at StrategyWiki because Extension:Scribunto is installed.

This page provides helpful documentation pertaining to the use of Lua on StrategyWiki.

Modules on SW
"Modules" are not pre-set libraries. They are pages that we have to create ourselves before being able to use any Lua code.
 * Module:Explode
 * Module:Sandbox

Basic syntax of calling a LUA function
This is only possible after a module has been created.

Examples

 * Sandbox


 * Testing the explode function inside of Module&#58;Explode


 * Testing the split function inside of Module&#58;Explode


 * Testing string.find function inside of Module&#58;Explode

The above numbers are the returned starting and ending values of where the string matches.

LUA basics

 * -- comments a line.
 * -- Multi-line comment "tags" --
 * Data type of all number variables are 64-bit doubles that can auto-store int values.
 * Single or double quotes are used to define strings.
 * Double brackets used to define multi-line strings.
 * Variable = nil will undefine the variable and process it through garbage collection.
 * Variable = {} will define a table; this is a constructor expression.

Example code
function p.find(frame) -- args: 1:string 2:delimiter character (divider character) 3:starting position (far left if not set) 4:set to 'true' if you want plain matching enabled. See http://lua-users.org/wiki/StringLibraryTutorial -- return string.find(frame.args[1],frame.args[2],frame.args[3],frame.args[4]) end