Jason Follas.com

Page History: The LUA 5.1 Programming Language


Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: 2007/09/06 14:42


Intro

WoW add-ons are developed using the LUA 5.1 programming language: LUA 5.1 Manual

Of course, the LUA language itself does not implement the WoW API, which uses an event-driven model, so simply reading the manual will not help you to write that killer add-on. But, you've got to crawl before you can run, so let's dive into some of the syntax features of LUA itself.

Reserved Keywords

A lot can be learned about a language just by knowing what words are reserved keywords (and thus, cannot be used as variable names).

and       break     do        else      elseif
end       false     for       function  if
in        local     nil       not       or
repeat    return    then      true      until   while

Arithmetic Operators

+  addition        1 + 2 => 3
-  substraction    2 - 1 => 1
*  multiplication  3 * 4 => 12
/  division        9 / 3 => 3
%  modulo          8 % 6 => 2
^  exponent        2 ^ 5 => 32

Relational Operators

== equality  
~= inequality
<  less-than
<= less-than or equal
>  greater-than
>= greater-than or equal

Logical Operators

false and nil are both considered false, everything else is true.

and  (returns first argument if false/nil, otherwise returns second argument)
or   (returns the first argument if not false/nil, otherwise returns the second argument)
not  (returns true or false, depending on the argument)

10  or  20  --> 10
10  and 20  --> 20
nil or  10  --> 10
nil and 10  --> nil

(work in progress)

ScrewTurn Wiki version 2.0.13. Some of the icons created by FamFamFam.