From FxCodeBaseWiki

Jump to: navigation, search



What is Lua?

Lua is an extremely fast, simple and powerful scripting language designed, implemented, and maintained at PUC-Rio in Brazil. The strengths of Lua have been well-proven by its usage in many time-critical applications, including real-time strategies such as World of Warcraft. Nowadays, Lua is in top 20 of the most popular programming languages in the world.

Lua official website:

What does Lua Look Like?


In terms of syntax, Lua is close to the Pascal family of programming languages (Pascal, ADA, Delphi). There is no syntax sugars, such as prefix/postfix operators or assignments as part of expressions, as in C++.

Compare the factorial function implemented in C++, Pascal, and Lua.


 int fact(int value)
     if (value == 0)
        return 1;
        return fact(value - 1) * value;


 function fact(n: integer): longint;
     if (n = 0) then
         fact := 1
         fact := n * fact(n - 1);


 function fact(n)
    if n == 0 then
       return 1;
       return fact(n - 1) * n;


In terms of programming concepts, the language closest to Lua is JavaScript:

  • Lua has no types. A variable can take any value.
  • Lua does not require explicit variable declaration. If the value has not be assigned before, it is just a nil value.
  • The interface of Lua classes (known as tables) is dynamically created simply by assigning the reference to the function.


The concept of tables is the most complicated concept for Lua newbies. Tables are everything in Lua - they are classes, hash tables (dictionaries), and even arrays.

Table as a hash table.

You can store and then retrieve a value inside the table using any key:

 -- create a table
 a = {};
 -- put value 123 into the table with key "onetwothree"
 a["onetwothree"] = 123;
 -- retrieve the value by the key

If the key is a string, you can use the dot operator (.) to assign or retrieve the values. The example below does exactly the same as the previous example:

 -- create a table
 a = {};
 -- put value 123 into the table with key "onetwothree"
 a.onetwothree = 123;
 -- retrieve the value by the key

You can mix the syntax as well. For example, this code is also correct and does the same:

 -- create a table
 a = {};
 -- put value 123 into the table with key "onetwothree"
 a.onetwothree = 123;
 -- retrieve the value by the key

Table as an array.

If you use an integer number as a key and values are assigned starting from key 1, sequentially, without gaps in the order, Lua (and LuaJIT) optimizer recognizes that part of the values assigned as an array. An alternative (and really faster) method of access is used in that case:

 local array, i;
 -- create a table
 array = {};
 -- fill the table
 for i = 1, 10, 1 do 
    array[i] = i * 20;
 -- now keys 1 to 10 are stored as an array
 -- but we are still able to add additional properties to the dictionary part of the table
 array.first_item = 1;
 array.last_item = 10;
 -- this (access to the array part)...
 b = a[5];
 -- faster than this (access to the dictionary part)
 c = a.first_item;

Table as a class.

A reference to a function can be also stored into the table.

 -- create a table
 math = {};
 -- create an inline function and store the reference into the table 
 math.abs = function (x) 
              if x < 0 then
                 return -x;
                 return x;
 b = math.abs(-10);

Looks exactly like a static method of the class, doesn't it? Now, what if we want to create instance methods? The instance methods must receive a reference to the table, mustn't they? Let's see.

 -- create a table
 mytable = {};
 -- create a property
 mytable.x = 0;
 -- create a method = function (_this) 
                   _this.x = _this.x + 1;

Now we can use it as:;

But other languages (except plain C) do not require passing this reference explicitly! Why Lua does? Well, for such case Lua has a "syntax sugar", the colon operator (:), so the above call can be written as:


Where is Documentation?

  • Standard Lua documentation is included into both online and offline versions of the Indicore SDK documentation.
  • You can always refer to the Lua official website:

Which Version of Lua is Used?

Indicore uses Lua 5.1.5 specification and LuaJIT 2.0 implementation of the virtual machine.

Is Indicore Compatible with 3rd-Party Lua Extensions?

Yes. However, as stated above, we use LuaJIT 2.0 instead of the original Lua virtual machine, which is literally API/ABI compatible with the original Lua VM implementation except an ability to save or load Lua byte-code. LuaJIT 2.0 has its own compiler which is not compatible with the original Lua VM.

So, just check whether the extension is compatible with LuaJIT.

This Article in Other Languages

Language: English  • Español • Français • Русский • 中文 • ‪中文(繁體)‬
Personal tools