< Variables and Values | UserGuide | Blocks >


Variables and their associated values need to be stored somewhere - and for lua, this is done in tables (for global values). Tables are just a collection of variables that are each associated with values.

For example:


When lua is starting, the first thing that is created is a table, which becomes the global table by associating it as the environment for the function that is then executed and which becomes the main function - which executes your code. The global table contains all the stuff we need to create our program - functions and variables that we need to do that. We can simply access the variables of the global table (to be correct, the global table is just the table for the main function in which we start to code, however, any function can have its own table that is used as the so called environment) by typing in our code. The code

print "Hello World"

looks up the value for "print" that is associated in our application with. In this case, this is a function value. The function is then called with "Hello World" as argument.