Lua Fundamentals

Lesson 1 of 6

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
  • print writes a line to standard output.
  • local declares 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.

📝 Lua Basics Quiz

Passing score: 70%
  1. 1.Which operator concatenates two strings in Lua?

  2. 2.Lua table and array indices start at 1 by convention, not 0.

  3. 3.Declaring a variable with the ____ keyword scopes it to the current block instead of making it global.