Learn how to use Lua MQTT to connect IoT devices. Covers pub/sub patterns, QoS levels, retained messages, will messages, and production deployment checklists.
Guides
Guides
In-depth guides for Lua developers.
- Lua MQTT: Connecting IoT Devices with Lightweight Messaging
- Cross-Platform Scripting with Lua
Cross-platform scripting with Lua: handle paths, line endings, and environment variables on Windows, macOS, and Linux. Write portable scripts that run anywhere.
- Dependency Management Patterns in Lua
Master Lua dependency management with luarocks, submodule imports, and inline bundles. Find the right approach for your project size and deployment target.
- Event Systems and Message Passing in Lua
Build event systems in plain Lua: callbacks, publish-subscribe, message queues, coroutines, and OpenResty request handling.
- Logging Patterns and Frameworks in Lua
Explore practical logging patterns for Lua: add timestamps and log levels, write to files, use LuaLogging for advanced needs, and build a structured logger.
- Designing Plugin Architectures in Lua
Designing plugin architectures in Lua: load plugins as modules, register hooks, handle lifecycle events, and sandbox untrusted code.
- Building Template Engines in Lua
Building template engines in Lua: string interpolation with gsub, pattern-based templates, buffered output with partials, escaping, and when to use LPeg.
- Finite Automata and Lexers in Lua
Build tokenizers and lexers in Lua with deterministic finite automata. Learn how DFAs work, recognize token patterns, and explore Lua patterns and LPeg.
- Scripting Redis with EVAL and Lua
Scripting Redis with EVAL and Lua: atomic server-side logic, rate limiters, counters, and replacing pipelines with single scripts.
- SQLite Lua: A Complete Integration Guide with lsqlite3
Learn SQLite Lua database integration with lsqlite3 and luasql. Covers queries, prepared statements, transactions, error handling, and OpenResty setup.
- Implementing State Machines in Lua
Implementing state machines in Lua using tables, metatables, and coroutines. Covers guard conditions, hierarchical states, and practical game patterns.
- Lua configuration: using Lua tables for flexible app settings
Lua configuration turns .lua files into powerful app settings. Load tables with loadfile, branch by environment, validate keys with metatables.
- Lua-C Interop: A Practical Guide
Master Lua-C interop with the official API: register C functions, call Lua from C, and move data safely across the language boundary.
- Writing World of Warcraft Addons in Lua
Writing World of Warcraft addons from scratch with Lua: the .toc structure, event-driven model, saved variables, slash commands, and the full WoW Lua API.
- Building Domain-Specific Languages in Lua
A guide to building domain-specific languages in Lua using closures and metatables. Design fluent APIs for configuration, validation, and query building.
- Functional Programming Patterns in Lua
Master functional programming patterns in Lua with map, filter, fold, composition, pipelines, and immutability — all within Lua's table-based style.
- Memory Optimization Techniques
Learn memory optimization techniques for Lua: fix leaks with object pooling, weak tables, and GC profiling to cut allocation rates in hot loops.
- Profiling Lua Code for Bottlenecks
Profiling Lua programs to find bottlenecks: os.clock() timing, debug.sethook() sampling, and LuaJIT's profiler. A practical workflow for real code.
- Working with Binary Data in Lua 5.3+
Serialize and deserialize binary data using string.pack, unpack, and packsize. Covers format specifiers, endianness, and common pitfalls.
- LuaJIT FFI: Calling C from Lua
Learn to use LuaJIT FFI for calling C functions and working with C data structures directly from Lua. No extension modules or C boilerplate required.
- LPeg Parsing in Lua: PEG Grammars, Captures, and the re Module
Learn LPeg parsing in Lua: PEG grammars, pattern captures, table and fold captures, and the re module for structured text processing.
- TCP and HTTP Networking in Lua with LuaSocket
Build TCP clients and servers with LuaSocket, send HTTP requests, parse URLs, and handle networking patterns in Lua. Covers timeouts and non-blocking I/O.
- Parsing and Generating JSON in Lua
Learn how to parse and generate JSON in Lua using dkjson, cjson, and json.lua with practical examples and common gotchas.
- Lua Performance Tips and Benchmarking
Lua performance tips: table pre-allocation, local caching, table.concat, and benchmarking. Techniques to write faster Lua code with measurable results.
- Serializing Lua Tables to Disk
Serializing Lua tables to disk with string concat, json.lua, MessagePack, and the C API. Examples for persisting configuration, game state, and cache data.
- Sorting Tables: Comparators and Stability
Sorting tables in Lua: learn table.sort(), write comparators for multi-field sorts, handle case-insensitive ordering, and build stable sort alternatives.
- Lua Closures: Upvalues and Practical Patterns
Learn how Lua closures capture upvalues as live references, with practical patterns for factory functions, private state, memoization, and currying.
- Error Handling Patterns and Best Practices
Master Lua error handling with practical patterns for nil-plus-error returns, guard clauses, safe wrappers, and batch error collection.
- The debug Library: Inspection and Hooks
Explore Lua's debug library for inspecting stack frames, local variables, and upvalues at runtime, plus hooks for tracing and profiling code execution.
- Writing Custom Iterators in Lua
Writing custom iterators in Lua, from stateless factories and closure-based loops to coroutine-driven traversals for graphs, trees, and streams.
- Lua's Garbage Collector Explained
Understand Lua's garbage collector: tri-color algorithm, incremental and generational modes, collectgarbage() tuning, weak references, and __gc finalizers.
- Sandboxing Lua for Safe Execution
Learn sandboxing Lua for safe code execution. Covers custom environments, metatable access controls, and execution limits with debug.sethook.
- Lua String Patterns vs Regular Expressions
Lua string patterns vs regex: learn magic characters, character classes, repetition modifiers, balanced pairs with %b, and the frontier pattern.
- Testing Lua Code with Busted: A Practical Guide
Practical patterns for testing Lua with Busted — running specific tests, structuring test suites, isolating state, and integrating with CI pipelines.
- How Lua Weak Tables Work and When to Use Them
How Lua weak tables let you hold references without blocking garbage collection. Covers all three modes, memoization caches, and observer patterns.
- Metatables and Metamethods in Lua
Learn how Lua metatables customize table behavior through __index, __newindex, and operator overloading to build object-oriented patterns and prototypes.
- Understanding Lua Environments and _ENV
Understanding Lua environments: how global variable lookups work through _ENV upvalues, sandbox code with custom environments, and build secure module systems.
- Filesystem Operations with LuaFileSystem
Learn filesystem operations in Lua with LuaFileSystem (lfs): working with directories, file attributes, timestamps, and file locking across platforms.
- MoonScript: CoffeeScript for Lua
MoonScript brings CoffeeScript syntax to Lua: classes, arrow functions, and comprehensions that compile to readable standard Lua with no runtime dependencies.
- Managing Packages with LuaRocks
Learn how managing packages with LuaRocks works: install, search, list, remove, and publish your own rocks to the luarocks.org repository.
- Penlight Batteries-Included Library: Lua Utility Guide
Penlight batteries-included library extends Lua with utilities for tables, strings, files, and config parsing. Practical examples included.
- Teal: Typed Lua That Compiles to Lua
Add types to Lua with Teal: a typed dialect compiling to plain Lua that catches bugs at compile time while running on any runtime from 5.1 through LuaJIT.