The name Lua comes from Portuguese meaning moon and is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications.
Lua was originally designed in 1993 as a language for extending software applications to meet the increasing demand for customization at the time.
Lua is cross-platform since the interpreter of compiled bytecode is written in ANSI C.
Lua has a relatively simple C API to embed into applications.
Let’s start with some information and basic examples, see also this online tool for lua with these examples:
- Lua is case-sensitive: and is a reserved word, example: And and AND are two other different identifiers;
- following words are reserved and we cannot use them as identifiers – variables for example:12345and break do else elseifend false for function ifin local nil not orrepeat return then true untilwhile
- comments on many rows start anywhere with :1--[[ this is a comment --]]
- a single row comment starts with a double hyphen is a punctuation mark (-), start a row commented with — anywhere outside a string, see:1-- this is a single row comment
- Global variables − all variables are considered global unless explicitly declared as local, see:1d = 5;
- Local variables − when the type is specified as local for a variable, its scope is limited with the functions inside their scope, see:1local x = 10
- Table fields − this is a special type of variable that can hold anything except nil including functions – can contain functions, but you can assign nil to a table field to delete it.
- These strings denote other tokens:1234+ - * / % ^ #== ~= <= >= < > =( ) { } [ ]; : , . .. ...
- There are 8 basic types in Lua:123456789101112nil type of the value nil whose main property is to be different from any other value.It usually represents the absence of a useful valueboolean values false and true (both nil and false make a condition false;any other value makes it true)number both integer and floating-point numbers (has internally two distinctrepresentations: integer and float)string arrays of characters (strings may contain any 8-bit character,including embedded zeros)function Lua functionsuserdata can hold arbitrary C data (corresponds to a block of raw memory)thread independent threads of execution used to implement coroutinestable arrays that can hold values of any type except nil
- Relational operators and always result in false or true:123456== equality~= negation of equality< smaller than> bigger than<= smaller or equal than>= bigger or equal than
- Bitwise operators:123456&: bitwise AND|: bitwise OR~: bitwise exclusive OR>>: right shift<<: unary bitwise NOT~: unary bitwise NOT
- Statements contains words like: If, For, While, Repeat and Table.
- Concatenation or combine:1234word1='-hello'word2=' world'-- result contains '-hello world'result=word1..word2
The next tutorial will be more complex.