Internationalisation
Bundled Plugins API
Lua Overview

What is Lua?

What do DaVinci Resolve, Adobe Photoshop Lightroom, Angry Birds, Apache HTTP Server, Apache Traffic Server, the Firefox web browser, MediaWiki, and World of Warcraft all have in common?
They are all extensible using the cross-platform Lua programming language!
"Lua" (pronounced LOO-ah) means "Moon" in Portuguese.
Lua is a powerful and fast programming language that is easy to learn and use and to embed into your application.
Lua is designed to be a lightweight embeddable scripting language and is used for all sorts of applications from games to web applications and image processing.
Lua is freely available for any purpose, including commercial purposes, at absolutely no cost, and using it requires no paperwork. Read the details in the license page.
For complete information, visit Lua's web site.

Tutorials

Here's some links to useful tutorials...

Beginners:

Programmers:

Advanced:

The Manual:

Crash Course

Introduction

  • Like JavaScript, Lua is a case sensitive language - "and", "And" or "AND" are not the same.
  • The following are Lua keywords:
1
and break do else elseif
2
end false for function if
3
in local nil not or
4
repeat return then true until while
Copied!
  • The following strings denote other tokens:
1
\+ - * / % ^ #
2
== ~= <= >= < > =
3
( ) { } [ ]
4
; : , . .. ...
Copied!
  • Literal strings can be delimited by matching single or double quotes (e.g. 'hello' or "hello")
  • A comment starts with a double hyphen (--) anywhere outside of a string. e.g.:
1
a=4 -- variable a is now 4!
Copied!

Values & Types

  • Lua is a dynamically typed language which means that variables do not have types; only values do.
  • There are 8 basic types in Lua:
  • nil - type of the value nil whose main property is to be different from any other value. It usually represents the absence of a useful value.
  • boolean - values false and true (both nil and false make a condition false; any other value makes it true)
  • number - real numbers
  • string - arrays of characters (strings may contain any 8-bit character, including embedded zeros)
  • function - Lua functions
  • userdata - can hold arbitrary C data (corresponds to a block of raw memory)
  • thread - independent threads of execution used to implement coroutines
  • table - arrays that can hold values of any type except nil

Variables

  • There are 3 kinds of variables:
  • Global Variables
  • Local Variables
  • Table Fields
  • Any variable is assumed to be global unless explicitely declared as local.
  • Before the first assignment to a variable, its value is nil.
  • Square brackets are used to index a table (e.g. value=table[x]). The first value in a table is at position 1 (and not 0 as for C arrays).

Statements

  • Lua allows multiple assignments. The syntax for assignments defines a list of variables on the left side and a list of expressions on the right side. The elements in both lists are separated by commas:
1
x,y,z = myTable[1],myTable[2],myTable[3]
Copied!
  • Relational operators (always result in false or true):
1
== equality
2
~= negation of equality
3
< smaller than
4
> bigger than
5
<= smaller or equal than
6
>= bigger or equal than
Copied!
  • If control structure (by example):
1
if value1==value2 then
2
print('value1 and value2 are same!')
3
end
Copied!
  • For control structure (by example):
1
for i=1,4,1 do -- count from 1 to 4 with increments of 1
2
print(i)
3
end
Copied!
  • While control structure (by example):
1
i=0
2
while i~=4 do
3
i=i+1
4
end
Copied!
  • Repeat control structure (by example):
1
i=0
2
repeat
3
i=i+1
4
until i==4
Copied!
  • Table operations (by example):
1
myTable={'firstValue',2,3} -- builds a table with 3 values
2
print(myTable[1]) -- prints the first element in the table
3
table.insert(myTable,4) -- appends the number 4 to the table
Copied!
  • Concatenation (by example):
1
a=' hello'
2
b=' world'
3
c=a..b -- c contains 'hello world'
Copied!
  • Length operator #:
1
stringLength=#'hello world'
2
tableSize=#{1,2,3,4,5}
Copied!
Last modified 1mo ago
Export as PDF
Copy link