luaguides

Tutorial series

Lua Fundamentals

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

  1. Installing Lua on Windows, macOS, and Linux

    Learn how to install Lua on any operating system, verify your installation, and write your first Lua script.

  2. Variables and Types in Lua

    Learn how Lua handles variables, understand the difference between local and global variables, and explore Lua's eight basic data types.

  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

    Learn how to define and use functions in Lua, including closures, variadic arguments, and best practices for writing modular code.

  5. Tables: Lua's Universal Data Structure

    Learn how tables in Lua work as arrays, dictionaries, and objects—all in one powerful data structure.

  6. Strings and Pattern Matching Basics

    Learn how to work with strings in Lua using the string library and pattern matching with Lua's powerful pattern syntax.

  7. Modules and the require System

    Learn how to organize Lua code into reusable modules using require, package.path, and best practices for dependency management.

  8. Error Handling with pcall and xpcall

    Learn how to handle errors safely in Lua using pcall and xpcall. Covers protected execution, error handlers, and when to use each function.

  9. Reading and Writing Files in Lua

    Learn how to read and write files in Lua using the io library...

  10. Pattern Matching Deep Dive

    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

    Learn how Lua tables store key-value pairs, choose the right iteration method, and apply metatable tricks for advanced patterns.

  13. Arrays and Lists in Lua

    Learn Lua tables as arrays: 1-based indexing, the # operator, table.insert, table.remove, table.concat, and building stacks, queues, and deques.