luaguides

Tutorials

Tutorials

Step-by-step series to learn Lua from scratch.

  1. Graph Representations in Lua

    Learn the two main ways to represent graphs in Lua: adjacency matrices and adjacency lists, with BFS and DFS implementations.

  2. The Lua C API: Stack and State

    Learn how Lua manages state with lua_State, how the virtual stack works, and how to push, query, and pop values from C.

  3. Coroutine Basics: Create, Resume, Yield

    Learn how to create, resume, and yield from Lua coroutines for cooperative multitasking.

  4. Producer-Consumer with Coroutines

    Learn how to implement the producer-consumer pattern in Lua using coroutines for efficient cooperative multitasking.

  5. Cooperative Multitasking Patterns

    Learn how to build cooperative multitasking workflows in Lua using coroutines with producer-consumer, scheduler, and pipeline patterns.

  6. Coroutine Wrappers and Iterators

    Discover how to use coroutine wrappers and iterators in Lua to build efficient generators and custom traversal functions.

  7. Async Patterns with Coroutines

    Learn how to implement asynchronous programming patterns using Lua coroutines for non-blocking operations

  8. Binary Trees and BSTs in Lua

    Learn how to implement binary trees and binary search trees in Lua with clear explanations and runnable code examples.

  9. Priority Queues and Heaps in Lua

    Learn how to implement priority queues and binary heaps in Lua using tables, with practical examples for task scheduling and event queues.

  10. Embedding Lua in a C Application

    Learn how to embed a Lua interpreter into your C programs to run Lua scripts, exchange data via a stack, and expose C functions to Lua.

  11. Writing C Extensions for Lua

    Learn how to write C modules that Lua can load with require(), covering stack management, module registration, userdata, and compilation.

  12. Userdata, Light Userdata, and Metatables in Lua

    Learn how Lua bridges C code with userdata types and uses metatables to define custom behavior for any value.

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

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

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

  16. Functions, Closures, and Varargs

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

  17. Tables: Lua's Universal Data Structure

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

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

  19. Modules and the require System

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

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

  21. Reading and Writing Files in Lua

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

  22. Pattern Matching Deep Dive

    Learn Lua pattern matching syntax for searching, extracting, and transforming strings with character classes, captures, and practical examples.

  23. Operator Overloading with Metamethods

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

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

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

  26. Getting Started with LOVE 2D

    Install LOVE 2D, understand the game loop, create windows, and draw your first shapes in Lua.

  27. Collision Detection Techniques

    Learn how to detect collisions between game objects in LÖVE2D using AABB, circle, and tile-based methods.

  28. Playing Music and Sound Effects in LÖVE2D

    Learn how to load, play, and control audio in LÖVE2D — from background music with looping to sound effects with volume and pitch control.

  29. Working with Tilemaps and STI

    Learn how to load, render, and manipulate tile maps in Love2D using the STI library

  30. Managing Game States and Scenes

    Learn how to structure your LÖVE games using hump.gamestate to handle menus, gameplay, pause screens, and transitions between parts of your application.

  31. Packaging and Distributing Your Game

    Learn how to package your LÖVE2D game into a .love file, create Windows executables, macOS app bundles, and distribute on itch.io.

  32. Every Lua Metamethod Explained

    A complete guide to every metamethod in Lua 5.4: arithmetic, comparison, __index, __call, __gc, __close, and more with runnable examples.

  33. Metatables: What They Are and Why They Matter

    Learn how metatables let you customize table behavior in Lua — from operator overloading to OOP inheritance and read-only tables.

  34. Building Classes in Lua with Metatables: OOP Step by Step

    Guide to building classes in Lua with metatables. Covers constructors, methods, the self parameter, private members, and inheritance patterns step by step.

  35. Single and Multiple Inheritance in Lua

    Learn how to implement inheritance in Lua using metatables, covering single and multiple inheritance patterns with practical examples.

  36. Mixins and Composition Patterns in Lua

    Learn how to use mixins and composition in Lua to add functionality to objects without the constraints of traditional inheritance.

  37. Getting Started with OpenResty

    Learn how to build powerful web applications and API gateways using OpenResty—the platform that combines Nginx with LuaJIT for dynamic request processing.

  38. Routing and Middleware in OpenResty

    Learn how OpenResty processes HTTP requests through phases, and how to implement routing and middleware using Lua scripts embedded in Nginx.

  39. Building a REST API with OpenResty

    Learn how to build a REST API with OpenResty and Lua, covering routing, request handling, JSON responses, and caching with shared dicts.

  40. Getting Started with Roblox Luau

    Learn the basics of Luau scripting in Roblox Studio, from variables and functions to handling events and building your first interactive game object.

  41. Scripting Game Objects and Services

    Learn how to create, navigate, and manipulate Roblox game objects using Luau, from the object hierarchy to key services and practical patterns.

  42. Building User Interfaces in Roblox

    Learn how to create interactive user interfaces in Roblox using ScreenGui, frames, text elements, and the TweenService animation API.

  43. Mocks, Stubs, and Spies in Lua

    Learn how to replace functions with test doubles in Lua using manual patterns and Busted's built-in stub and spy APIs for reliable unit tests.

  44. Measuring Code Coverage in Lua

    Learn how to track which lines of your Lua code run during tests using LuaCov and busted's built-in coverage reporting.

  45. Setting Up CI for Lua with GitHub Actions

    Automate your Lua tests with GitHub Actions. Run busted on multiple Lua versions, measure coverage with lua-cov, and enforce quality gates in CI.

  46. Test-Driven Development Patterns in Lua

    Learn to drive your Lua code design through tests. Covers Red-Green-Refactor, Arrange-Act-Assert, fixtures, stubs, and TDD patterns with busted.

  47. Getting Started with Testing in Lua

    Learn how to write and run unit tests in Lua using the Busted framework, from basic assertions to setup/teardown and stubbing.

  48. Using the Busted Test Framework

    Learn how to write, run, and organize unit tests in Lua with the Busted BDD framework, including spies, stubs, mocks, and lifecycle hooks.

  49. Scripting Neovim with Lua

    Learn how to configure and extend Neovim using Lua — from your first init.lua to working with buffers, windows, autocmds, and keymaps.

  50. Using Redis from Lua in OpenResty

    Learn how to connect to Redis from OpenResty using lua-resty-redis — covering connection management, get/set ops, pipelining, Pub/Sub, and pooling.

  51. Rate Limiting with Lua and Shared Dicts

    Learn how to implement rate limiting in OpenResty using ngx.shared.DICT, covering fixed window counters, token buckets, and lua-resty-limit-traffic.

  52. RemoteEvents and Client-Server Communication in Roblox

    Learn how RemoteEvents and RemoteFunctions bridge the gap between Roblox server scripts and client scripts for multiplayer game communication.

  53. Saving Player Data with DataStores

    Learn how to use Roblox DataStoreService to persist player coins, inventory, and progress between sessions.

  54. Building a Complete Roblox Game

    Build a coin collection game in Roblox Studio from scratch — covering leaderstats, DataStoreService persistence, RemoteEvents, and player UI.

  55. Stacks and Queues in Lua

    Implement stacks and queues in Lua using tables. Learn push/pop, the O(n) trap with table.remove(t, 1), and how to build an efficient circular buffer.

  56. Implementing Sets in Lua

    Learn how to implement and use sets in Lua using tables with true sentinel values, including set operations, iteration gotchas, and read-only proxies.

  57. Singly and Doubly Linked Lists in Lua

    Learn how to implement singly and doubly linked lists in Lua using tables, with performance comparisons and practical examples.