luaguides

Tutorial series

Lua Fundamentals

13 tutorials — follow in order for the best learning path.

  1. Installing Lua on Windows, macOS, and Linux

    Install Lua on macOS, Windows, and Linux — use Homebrew, Scoop, or your package manager to set up the interpreter and run your first script.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. Strings and Pattern Matching Basics

    Master Lua strings pattern matching: concatenation, capturing, validation, and string patterns for gsub, gmatch, and text processing in Lua.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. Operator Overloading with Metamethods

    Learn how metatables and metamethods enable operator overloading in Lua, letting you define custom behavior for your own tables.

  12. 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.

  13. 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.