Polyglot
Languages Lua
Volume Lua

Lua

A small, dynamically typed scripting language designed for embedding in host applications. Found in game engines, application scripting, and as the configuration substrate for several systems.

Paradigms
imperative · functional
Typing
dynamic
Memory
gc
Version
5.4
First released
1993

Lua is a small, dynamically typed, embeddable scripting language. The reference implementation is written in clean ANSI C and consists of a few thousand lines of source; the resulting interpreter is small enough to bundle into any host application without significant binary-size cost. The language is designed for use as a guest — the host application provides the surrounding execution environment, exposes its own data and functions to the Lua interpreter, and invokes Lua scripts to perform the customisable parts of its behaviour. The data model is centred on a single composite type, the table, which serves simultaneously as array, hash, record, and prototype for the language’s implementation of object-oriented programming. Memory is managed by an incremental tracing garbage collector; concurrency is provided by coroutines, cooperatively scheduled stackful suspensions native to the language.

History

Lua was created by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes at Tecgraf, the Computer Graphics Technology Group at Pontifical Catholic University of Rio de Janeiro (PUC-Rio), in 1993. The language was initially developed to replace two earlier internal scripting languages used at Tecgraf for engineering and oil-industry applications. The name Lua is the Portuguese word for moon, chosen as a complement to an earlier internal language named SOL, the Portuguese word for sun. Lua 1.0 was released in July 1993. Subsequent versions have refined the language and the virtual machine, with each major version introducing changes that are deliberately not backward compatible: Lua 5.1 (2006) consolidated the standard library; Lua 5.2 (2011) introduced goto and a new environment model; Lua 5.3 (2015) introduced 64-bit integers as a distinct subtype; Lua 5.4 (2020) introduced a generational garbage collector and to-be-closed variables. LuaJIT is a separate, partially compatible implementation focused on just-in-time-compiled performance, widely used in games, networking middleware, and the OpenResty web platform. Luau, derived from Lua 5.1 by Roblox, adds a static type system and additional safety features.

Hello world

print("Hello, world!")

Execution with the reference interpreter:

lua hello.lua

Lua is most commonly invoked from a host application rather than as a standalone interpreter. Embedding requires linking the Lua C library and using the C API to create a Lua state, load a script, and exchange values with it. Application scripting through Lua appears in Adobe Lightroom, Roblox (through Luau), Redis (server-side scripting), Nginx (through the OpenResty platform), World of Warcraft (user-interface customisation), and many embedded and game-development contexts. The package manager LuaRocks distributes third-party modules.