Est. 1993 Beginner

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

Paradigm Multi-paradigm: Scripting, Procedural, Prototype-based Object-Oriented, Functional
Typing Dynamic, Strong
First Appeared 1993
Latest Version Lua 5.5.0 (2025)

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
-- Array-style
fruits = {"apple", "banana", "cherry"}

-- Dictionary-style
person = {name = "Alice", age = 30}

-- Mixed
config = {
    debug = true,
    servers = {"host1", "host2"},
    ["special-key"] = "value"
}

Metatables and Metamethods

Metatables allow customizing how tables behave, enabling operator overloading and object-oriented patterns:

1
2
3
4
5
6
7
8
local mt = {
    __add = function(a, b)
        return {x = a.x + b.x, y = a.y + b.y}
    end
}
local v1 = setmetatable({x = 1, y = 2}, mt)
local v2 = setmetatable({x = 3, y = 4}, mt)
local v3 = v1 + v2  -- Uses __add metamethod

Coroutines

Lua provides first-class coroutines for cooperative multitasking:

1
2
3
4
5
6
7
8
9
co = coroutine.create(function()
    for i = 1, 3 do
        print("Coroutine:", i)
        coroutine.yield()
    end
end)

coroutine.resume(co)  -- Prints: Coroutine: 1
coroutine.resume(co)  -- Prints: Coroutine: 2

Lua in Game Development

Lua dominates game scripting for several reasons:

  1. Easy Integration: The C API makes embedding straightforward
  2. Fast Enough: LuaJIT rivals C++ performance for many tasks
  3. Sandboxable: Easy to restrict what scripts can access
  4. Hot Reloading: Scripts can be modified without recompiling the game
  5. 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

FeatureLuaPythonJavaScript
Size~200KB~15MBVaries
Arrays1-indexed0-indexed0-indexed
OOPPrototype-basedClass-basedPrototype-based
EmbeddingExcellentPossibleDifficult
TypingDynamicDynamicDynamic

Modern Lua

Lua continues to evolve while maintaining backward compatibility:

  • Lua 5.4 (2020) introduced a new generational garbage collector and const/close variables
  • 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

1993
Lua created at PUC-Rio (Pontifical Catholic University of Rio de Janeiro) in Brazil
1994
Lua 1.0 released - a simple data-description language with tables as the only data structure
1996
Lua 2.0 adds pattern matching and long strings
1997
Lua 3.0 introduces tag methods (precursor to metatables) and anonymous functions
2003
Lua 5.0 released with coroutines, metatables replacing tag methods, and proper lexical scoping
2006
Lua 5.1 adds module system and incremental garbage collection; LuaJIT project gains traction
2011
Lua 5.2 introduces bitwise operators, goto statement, and light C functions
2015
Lua 5.3 adds native integer support and integer-based bitwise operators
2020
Lua 5.4 released with new generational garbage collector and const/close variables
2025
Lua 5.5.0 released with continued improvements to the language

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

Scheme SNOBOL Modula CLU C++

Influenced

Io GameMonkey Squirrel MiniD Red

Running Today

Run examples using the official Docker image:

docker pull nickblah/lua:5.4-alpine

Example usage:

docker run --rm -v $(pwd):/app -w /app nickblah/lua:5.4-alpine lua hello.lua

Topics Covered

Last updated: