Lua – The beginning in lua programming

Published on Author gryzliLeave a comment

Lua is fast, light-weight and powerfull scripting language.

If we trust the creators website, Lua must be the fastest interpreted programming language, which is a big reason to love it.


Lua Programming – The basis

The is no “line ending delimiters” in lua ,but if you like, you can use “;” as delimiter. The line delimiting is the same as with BASH.

Using comments

How to comment a line in lua ?

How to make a multi-line comment in lua ?

Below are the answers ..


Single-line comments start with “–”

Multi-line comments


Defining variables

In Lua there is no such thing as “array”, “hash”, “associative array” …etc. There is the “table” object which could be used for various types of arrays/hashes.

It is really important that you define the variable as table object, before trying to use it as such.

Below you will see how to define simple array and how to define hash in Lua.

Define a table object ( used instead of arrays/assoc arrays, hashes… etc)


Define a variable:



Not defined variable is “nil” .


Define a local variable

(By default in Lua all variables are Global)



Here we also have plenty of statements, which include if/then/else,  while/do, repeat/until, for/do

Here is the little examples showing the statements you could use




Here we will define simple function, which will “add” two numbers and return the result.



Working with files

Working with files is simple, you are able to do standard open calls for reading and writing files.

Writing a file


Reading from file


External resources

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha * Time limit is exhausted. Please reload CAPTCHA.