Skip to main content

Lua

Pronunciation
LOO-uh
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/lua

In short

Lua is a small, fast scripting language designed to be embedded in other applications, making it popular for game scripting, plugins and configuration.

What is Lua?

Lua is a lightweight scripting language created in 1993 at the Pontifical Catholic University of Rio de Janeiro in Brazil; its name means "moon" in Portuguese. It was designed to be embedded inside other programs: the whole interpreter is a small C library that an application can include, so users can write Lua scripts to extend or configure that application without recompiling it.

Lua is dynamically typed and deliberately minimal. Its only built-in data structure is the table, which serves as array, dictionary, object and module all at once, and metatables let you customize how tables behave to build classes or overload operators. Lua counts array positions from 1, supports first-class functions and closures, and has coroutines for cooperative multitasking. Memory is managed by a garbage collector, and the separate LuaJIT project provides a very fast just-in-time compiler.

Lua is widely used for scripting in video games and game engines, for plugins and configuration in text editors, for scripts that run inside web servers, proxies and databases, and in embedded devices. Embedding Lua is like giving an appliance a slot for recipe cards: the machine does the heavy work in fast native code, and the scripts decide what it should do.

Lua is often compared with Python and JavaScript, which are also dynamic scripting languages. The main difference is purpose: Python and JavaScript ship large standard libraries and are mostly used to write whole applications, while Lua is tiny, easy to embed in a C or C++ host and usually runs inside another program. Some platforms maintain their own Lua dialects that add features such as gradual typing on top of the core language.

Key takeaways

  • Lua is a tiny scripting language designed to be embedded inside other applications.
  • Tables are its single, flexible data structure for arrays, maps and objects.
  • Arrays in Lua start at index 1 by convention.
  • It is widely used for game scripting, editor plugins and server-side extensions.

Example

Tables and methods in Lualua
-- A table works as both an array and a dictionary
local player = { name = "Ada", score = 0, items = { "sword", "map" } }

function player:addPoints(points)   -- ':' passes the table as self
  self.score = self.score + points
end

player:addPoints(10)
print(player.name .. " has " .. player.score .. " points")  -- Ada has 10 points

for i, item in ipairs(player.items) do   -- arrays start at 1
  print(i, item)                         -- 1 sword, then 2 map
end

Readers ask

Why do Lua arrays start at 1?

Lua was designed with engineers and non-programmers in mind, who were used to counting from 1, so its standard library and length operator treat 1 as the first index. You can store a value at index 0, but functions like ipairs start at 1.

Is Lua hard to learn?

No. Lua has a small syntax and only a handful of concepts, so many people learn the basics in a day, which is one reason games and tools choose it for user scripts.

Is Lua faster than Python?

The standard Lua interpreter is often faster than CPython for simple scripts, and LuaJIT can be much faster still. Real performance depends on the workload and on how much work happens in native libraries.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings