Lua
A lightweight, high-level scripting language designed for embedded use in applications, widely used in game development.
Created by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
Lua is a powerful, lightweight scripting language designed to be embedded within applications. Its name comes from the Portuguese word for “moon,” reflecting its Brazilian origins. Despite its small footprint—the reference implementation is under 200KB—Lua has become one of the most popular scripting languages in the game development industry.
History & Origins
Lua was created in 1993 at the Pontifical Catholic University of Rio de Janeiro (PUC-Rio) in Brazil by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes. The language emerged from a need to develop flexible configuration and data-description tools for Petrobras, the Brazilian national oil company.
At the time, Brazil had import restrictions (market reserve policies) that limited access to computer software, forcing Brazilian developers to create their own tools. This constraint led to the creation of SOL (Simple Object Language) and DEL (Data Entry Language), which eventually evolved into Lua.
Design Philosophy
Lua’s design reflects several core principles:
- Simplicity: Small core with powerful extensibility mechanisms
- Portability: Written in ANSI C, runs on virtually any platform
- Embeddability: Designed to be embedded in larger applications
- Efficiency: Fast execution with minimal memory footprint
- Flexibility: Everything is a table (associative arrays)
Key Features
Tables as Universal Data Structure
Lua’s single complex data type is the table—an associative array that can represent arrays, dictionaries, objects, modules, and even namespaces:
| |
Metatables and Metamethods
Metatables allow customizing how tables behave, enabling operator overloading and object-oriented patterns:
| |
Coroutines
Lua provides first-class coroutines for cooperative multitasking:
| |
Lua in Game Development
Lua dominates game scripting for several reasons:
- Easy Integration: The C API makes embedding straightforward
- Fast Enough: LuaJIT rivals C++ performance for many tasks
- Sandboxable: Easy to restrict what scripts can access
- Hot Reloading: Scripts can be modified without recompiling the game
- Designer-Friendly: Non-programmers can learn Lua basics quickly
Major game engines using Lua include LÖVE 2D, Corona SDK, Defold, and Godot (via third-party). Even engines not built on Lua often support it for modding.
LuaJIT
Mike Pall’s LuaJIT is a Just-In-Time compiler for Lua that achieves remarkable performance—often within 2-4x of optimized C code. Many performance-critical applications use LuaJIT instead of the reference interpreter. However, LuaJIT is based on Lua 5.1 and doesn’t support all features of newer Lua versions.
Lua vs. Other Scripting Languages
| Feature | Lua | Python | JavaScript |
|---|---|---|---|
| Size | ~200KB | ~15MB | Varies |
| Arrays | 1-indexed | 0-indexed | 0-indexed |
| OOP | Prototype-based | Class-based | Prototype-based |
| Embedding | Excellent | Possible | Difficult |
| Typing | Dynamic | Dynamic | Dynamic |
Modern Lua
Lua continues to evolve while maintaining backward compatibility:
- Lua 5.4 (2020) introduced a new generational garbage collector and
const/closevariables - Lua 5.5 (2025) continues refinements to the language and runtime
- Luau (Roblox’s Lua fork) adds gradual typing and performance improvements
- Neovim’s adoption has brought Lua to millions of developers as a configuration language
Despite being over 30 years old, Lua remains relevant wherever lightweight, embeddable scripting is needed—from game consoles to network appliances to embedded systems.
Timeline
Notable Uses & Legacy
World of Warcraft
Blizzard's massively popular MMO uses Lua for its entire add-on system, enabling millions of user-created UI modifications.
Roblox
The gaming platform uses Luau, a Lua derivative, as its primary scripting language for creating games.
Adobe Lightroom
Adobe's professional photo editing software uses Lua for plugins and automation scripting.
Nginx (OpenResty)
The OpenResty web platform embeds Lua directly into Nginx for high-performance web applications.
Redis
The popular in-memory database uses Lua for server-side scripting and atomic operations.
Neovim
The modern Vim fork uses Lua as its primary configuration and plugin language, replacing VimScript.
Language Influence
Influenced By
Influenced
Running Today
Run examples using the official Docker image:
docker pull nickblah/lua:5.4-alpineExample usage:
docker run --rm -v $(pwd):/app -w /app nickblah/lua:5.4-alpine lua hello.lua