Install Lua on macOS, Windows, and Linux — use Homebrew, Scoop, or your package manager to set up the interpreter and run your first script.
Tutorial series
Lua Fundamentals
13 tutorials — follow in order for the best learning path.
- Installing Lua on Windows, macOS, and Linux
- Variables and Types in Lua: A Complete Guide
Learn Lua variables and types — local vs global scope, nil, boolean, number, string, function, table, userdata, thread. Practical examples for each.
- Control Flow in Lua: if, for, while, and repeat
Master Lua control flow with if/elseif/else, for loops, while loops, and repeat...until. Build decision-making into your programs.
- Functions, Closures, and Varargs
Master Lua functions, closures, and varargs. Learn how to define functions, capture state with closures, and handle variable-length argument lists.
- Tables: Lua's Universal Data Structure
Master Lua tables — the language's only built-in data structure. Learn how Lua tables serve as arrays, dictionaries, and objects with practical code examples.
- Strings and Pattern Matching Basics
Master Lua strings pattern matching: concatenation, capturing, validation, and string patterns for gsub, gmatch, and text processing in Lua.
- Modules and the require System
Understand how Lua modules require and expose reusable code. Learn package.path usage, preload custom loaders, dependency management, and modern patterns.
- Error Handling with pcall and xpcall
Learn error handling in Lua using pcall and xpcall. Covers protected execution, error handlers, and when to use each function.
- Reading and Writing Files in Lua
Master reading writing files in Lua with the io library. Covers open modes, line iteration, append strategies, and best practices for safe file I/O.
- Pattern Matching in Lua: Strings, Captures, and Modifiers
Learn Lua pattern matching syntax for searching, extracting, and transforming strings with character classes, captures, and practical examples.
- Operator Overloading with Metamethods
Learn how metatables and metamethods enable operator overloading in Lua, letting you define custom behavior for your own tables.
- Hash Maps and Dictionaries in Lua
Build hash maps in Lua with tables: string vs integer keys, `pairs()` vs `ipairs()`, the array part vs hash part, and metatable techniques.
- Lua arrays and lists: a complete table indexing guide
Master Lua arrays and lists by learning 1-based indexing, the # operator, table.insert, and how to build stacks, queues, and deques from plain tables.