This tutorial follows John Sonmez Youtube tutorial and 游戏大师课 Youtuber tutorial for basics of Lua.
Lua is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications. Lua is cross-platform, since the interpreter of compiled bytecode is writtten in ANSI C, and Lua has a relatively simple C API to embed it into applications.
Lua was originally designed in 1993 as a language for extending software applicationss to meet the increasing demand for customization at the time. It provided the basic facilities of most procedural programming languages, but more complicated or domain-specific features were not included; rather, it included mechanisms for extending the language, allowing programmers to implement such features. As Lua was intended to be a general embeddable extension language, the designers of Lua focused on improving its speed, portability, extensibility, and ease-of-use in development. (from wikipedia)
- nil
- boolean
- number
- string
- userdata
- function
- thread
- table
- Arthmetic (+, -, *, /, ^, %)
- Relational (<, >, <=, >=, ==, ~=)
- Note: not equal ~= in Lua
- Logical (and, not, or)
- Other
- Concatenation
- "Hi" .."there"
- Length
- #suckers
- Concatenation
if boolean expresion then
-- do something
else
-- do something else
end
- While - while boolean expression do something end
- Repeat - repeat something until boolean expression
- For (Numberic) - for variable = start, end, step do something end
- For (Generic) - for k, v in iterator do something end
By default, all variables in Lua are globally scoped
function countStringLengths(...)
--do stuff
a, b, c = ...
end
Ex. (1): grades = {1, 2, 3}
Ex. (2): grades = {"John" = 89, "Steam" = 90}
Note: the index of tables in Lua starts from 1 not 0
- __index
- __newindex
- Operators
- __add
- __sub
- __mul
- ...
- __call
- __tostring
- Basic
- Package
- String
- Table
- I/O
- Operating System
- Debug
and | break | do | else |
elseif | end | false | for |
function | if | in | local |
nil | not | or | repeat |
return | then | true | until |
while |