LUA / World Of Warcraft
LUA Crib Sheet
(Last updated: Oct 1st 2006)

Flow of Control
Other Items of Interest



Operation Operator Notes
String concatenation .. "Hello " .. "World"
("Hello " + " World" will NOT work)
Equality == if (x == y)
Inequality ~= if (x ~= y)
Not not  
<, >, <=, >= <, >, <=, >= Work with both numeric and string values
AND and AND and OR are unusual if the arguments are not boolean.
x and y -- returns x if x != false, otherwise returns y
x or y -- returns x if x == false (or nil), otherwise returns y
This can be used to default values. For example, a = b or "default"
Also, x and y or z equates to a ? b : c
OR or
Null test == nil  



Function Description
tostring(anything) Converts anything to a string
string.format(format, args) Supported template chars:

%s = string
%d = decimal
%c = char
%f = floating point number (%g = compact fp number)
%x = hex (%X = uppercase hec)

string.find(s1, s2) Returns the index of s2 in s1
string.len("abcde") Returns the string length
string.lower("ABCDE") Converts to lowercase
string.upper("abcde") Converts to uppercase
string.sub("abcde", from)
string.sub("abcde", from, to)
Returns string subsections


Function Description
table.insert(myTable, newValue) APPENDs newValue
table.insert(myTable, newValue) Inserts newValue
table.insert(myTable, index, newValue) Get the size of the table
table.getn(myTable) Calls function for each item in the table
table.foreachi(mytable, function) Based on the index of the item. Note the trailing 'i' on foreachi. t = {1,2,3,4,5}
table.foreach(mytable, function) Calls function for each item in the table based on the key of the item (myTable["key"] = "123" or t = {a="1", b="2"})
table.sort(myTable, function(a,b) return a>b end) Sorts the table using the logic in the provided function.



Flow of control

Other Items of interest