Tutorial by Examples

Binaries Lua binaries are provided by most GNU/Linux distributions as a package. For example, on Debian, Ubuntu, and their derivatives it can be acquired by executing this: sudo apt-get install lua50 sudo apt-get install lua51 sudo apt-get install lua52 There are some semi-of...
Single-line comments in Lua start with -- and continue until the end of line: -- this is single line comment -- need another line -- huh? Block comments start with --[[ and end with ]]: --[[ This is block comment. So, it can go on... and on... and on.... ]] Block comme...
Usually, Lua is being shipped with two binaries: lua - standalone interpreter and interactive shell luac - bytecode compiler Lets say we have an example program (bottles_of_mate.lua) like this: local string = require "string" function bottle_take(bottles_available) lo...
variables var = 50 -- a global variable print(var) --> 50 do local var = 100 -- a local variable print(var) --> 100 end print(var) --> 50 -- The global var (50) still exists -- The local var (100) has gone out of scope and can't be accessed any longer. types num = 20 -- a ...
Sometimes Lua doesn't behave the way one would think after reading the documentation. Some of these cases are: Nil and Nothing aren't the same (COMMON PITFALL!) As expected, table.insert(my_table, 20) adds the value 20 to the table, and table.insert(my_table, 5, 20) adds the value 20 at the 5th po...
This is hello world code: print("Hello World!") How it works? It's simple! Lua executes print() function and uses "Hello World" string as argument.

Page 1 of 1