Codectionary / Developer documentation / Lua

Meet Lua, the small embeddable language created at PUC-Rio, and choose a clear path from a first script to modules and application scripting.

File extension
.lua
Runs in
Lua interpreter or a host application

What Lua is

Lua is a small, dynamically typed programming language designed to be embedded in other applications. A host program can expose its own objects and functions to a Lua script, allowing behaviour to change without rebuilding the host. Lua also has a standalone interpreter, so you can learn the language without an embedding application.

Lua originated at PUC-Rio in Brazil. Roberto Ierusalimschy, Luiz Henrique de Figueiredo and Waldemar Celes created it in 1993 to meet scripting and configuration needs. The language has evolved through several release lines. Check the Lua versions page for the current release, and check a host application’s documentation before using newer syntax: embedded hosts can ship a different Lua version or a derivative.

How a Lua script runs

A .lua file is plain-text source code. With the standalone interpreter, the lua command loads the file, checks its syntax and executes it in the Lua runtime; the official implementation uses bytecode and a virtual machine internally. An embedded application instead starts its own Lua state and decides which application functions are available. The language can be the same while the host-provided API is different.

The first example creates a local variable and joins strings with .. before printing the message. local limits the name to its scope. print writes to the terminal in the standalone interpreter; a host may capture output elsewhere. Lua tables provide flexible collections, functions group behaviour, and modules let files share code. These ideas are more useful to learn first than memorising every library function.

Where Lua is useful

Game engines and applications embed Lua so creators can express game rules, user-interface behaviour or extensions while the host supplies its own engine features. Developers also use standalone Lua for small command-line tools, configuration and automation. The benefit is a compact language with a straightforward C embedding interface; the limitation is that standard Lua alone does not provide the browser, operating-system or game APIs of a particular host.

Roblox uses Luau, a language derived from Lua 5.1, rather than the current standard Lua release. Choose the Luau path when you want Roblox scripting or Luau’s type checker. Do not paste Roblox examples into a normal Lua interpreter: names such as game and workspace are provided by the Roblox engine.

Lua in Codectionary’s Playground

The Playground lets you select Lua and edit or highlight a snippet, but it does not execute Lua. There is no Lua program output panel to inspect there. Use an installed lua interpreter to run the examples in these guides; output and errors appear in the terminal. The browser-based HTML and JavaScript preview is a different execution environment.

A beginner-to-advanced path

Start with the installation guide and a first .lua file. Next learn values, local variables, operators, conditionals and loops. Practise tables and functions by building a small text-based task; then learn modules, errors and library use with LuaRocks. Once those foundations are comfortable, explore coroutines, metatables and embedding only when a real project calls for them.

If your goal is Roblox, switch to the Luau overview after learning the shared basics. Study script placement and the client/server boundary before building multiplayer features.

  1. Install Lua or use an existing interpreter.
  2. Run the first .lua program and change its output.
  3. Learn tables, control flow, functions and modules.
  4. Apply those skills in a host application or explore advanced features.

Syntax

local name = "Codectionary"
print("Hello, " .. name .. "!")

Examples

A local value and a printed greeting

Run with lua hello.lua after saving the snippet in that file.

local name = "Codectionary"
print("Hello, " .. name .. "!")
  1. local creates a name visible in this file’s current scope. The value is a string, which is text inside quotation marks.
  2. .. joins the fixed greeting, name and exclamation mark. print sends Hello, Codectionary! to the terminal when the file runs.
  3. Change the name and rerun the file to confirm that the script uses the saved value.

Group a calculation in a function

Run as a standalone Lua file; the terminal prints 12.

local function total(price, quantity)
    return price * quantity
end

print(total(4, 3)) -- 12
  1. local function defines total with two parameters, price and quantity. return gives the multiplication result back to the caller.
  2. total(4, 3) supplies the arguments; print displays the returned number. The comment after -- explains the expected output and is not executed.
  3. A small billing or inventory script could reuse the same calculation for many items.

Lua: background & uses

Used for
Game scripting, Application extensions, Embedded systems
Created by
Roberto Ierusalimschy, Luiz Henrique de Figueiredo and Waldemar Celes at PUC-Rio
First released
1993 · first version
Version / standard
Lua 5.5

Current stable release line. Embedded applications may ship an older Lua runtime.

In the real world

Facts checked 8 September 2026. Product links describe documented uses.

Best practices

  • Confirm which Lua version your host embeds before copying an example.
  • Use local names to avoid accidental globals.
  • Run plain Lua examples with a real interpreter; Codectionary’s Playground is an editor for Lua.

Runtime & versions

Lua interpreter or a host application. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Lua reference manuals

Specifications & further reading