Codectionary / Developer documentation / Lua

Lua Variables & Values

Lua uses local for scoped variables. Its basic value types include nil, boolean, number, string, function, table, thread, and userdata.

About Lua

Lua is a small, embeddable scripting language. Applications can include a Lua interpreter to let developers extend behaviour, configure features or write game logic without rebuilding the whole program.

  • 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. Links open the sources; examples describe specific products or documented uses.

Syntax

local name = "Ada"
local active = true
print(name)

Examples

A small working example

Follow the values through this example, then change one input.

local name = "Ada"
local lessons = 3
print(name .. " completed " .. lessons .. " lessons")

Declaring local values

A small, runnable example of this syntax.

local name = "Ada"
local visits = 3
print(name .. " has " .. visits .. " visits")

Best practices

  • Declare variables local by default to avoid accidentally changing global state.
  • Keep examples small while learning, then combine the idea with a real project.

At a glance

Purpose
Lightweight scripting and embedding
File extension
.lua
Runs in
Lua interpreter or a host application
Usually used with
Host APIs and Lua modules

In plain English

Lua names refer to values. local keeps a variable within its lexical scope, and an uninitialised local starts as nil.

What you’ll learn

  • Declare a local.
  • Use nil intentionally.
  • Read Lua truthiness correctly.

Breaking down the syntax

local
Declares a lexically scoped variable.
nil
Represents absence of a value.
..
Concatenates strings (and numbers via conversion).

How it works

Declare

Introduce a local name.

Assign

Give it a value.

Use

Read it within its scope.

When should I use this?

Prefer local names for script state that should not be placed in the environment.

Common mistakes

A common trap

Only false and nil are false in a condition; zero is truthy.

Incorrect

if 0 then print("zero is false") end

Corrected

if 0 then print("zero is truthy in Lua") end

Compare approaches

  • local name: Limit a variable to a lexical scope.
  • Bare name assignment: Assign through the environment when no local binding applies.

Explore deeper

Lua and host languages

A host application may expose extra APIs or a related dialect, such as Luau. Check its documentation before assuming every host has the same syntax and library functions as standard Lua.

Specifications & further reading

Related Lua documentation