Why Lua? Getting Started
Lua is a small, fast, embeddable scripting language. You'll rarely run a "Lua application" on its own, instead, Lua gets embedded inside something bigger: game engines (Roblox, Love2D, World of Warcraft addons), Neovim configuration, and even network appliances.
Why it's popular for embedding
- Tiny and fast, the reference interpreter is a few hundred KB and famously quick for a dynamic language.
- Simple to embed, a C program can create a Lua interpreter, hand it data, and call Lua functions in only a few lines.
- Small core language, few keywords, one data structure (the table) that does almost everything.
Your first script
Lua
Run it with:
lua hello.lua
printwrites a line to standard output.localdeclares a variable scoped to the current block, without it, a variable is global by default, almost always a mistake...is the string concatenation operator (Lua does not overload+for strings the way JavaScript does).
NOTE
Lua array/table indices start at 1, not 0. This trips up almost everyone coming from C-family languages, and it's worth committing to memory right now.