Skip to content
AgileLogics
5 min read

Lua Versions, LuaJIT, and Luau

Prerequisites: Performance

"Lua" in the wild means one of several related languages. Knowing which one your host runs saves a lot of confusion.

Version Used by Notable features
Lua 5.1 (2006) older embeds, World of Warcraft the classic baseline
LuaJIT 2.1 Neovim, LÖVE, OpenResty, many games 5.1 syntax + JIT compiler + FFI + some 5.2 features (goto)
Lua 5.2 (2011) _ENV, goto, bit32 library
Lua 5.3 (2015) integers, //, bitwise operators, utf8
Lua 5.4 (2020) Redis 7+ (partly), many embeds <const>, <close>, generational GC, new random generator
Lua 5.5 (2025) global declarations, read-only loop variables, more compact arrays
Luau Roblox Lua 5.1 based, gradual typing, +=, continue, string interpolation

Writing portable code

local unpack = table.unpack or unpack          -- 5.1 / LuaJIT have global unpack
local version = _VERSION
print(version:match("^Lua 5%.%d$") ~= nil)
print(type(unpack))
print(math.type and math.type(1) or "no integer subtype")
true
function
integer

Things that differ most often:

  • Integers — 5.1/LuaJIT have only floats: 7 // 2 doesn't exist, and 3 / 1 prints 3 rather than 3.0.
  • Bitwise operators — LuaJIT uses the bit library (bit.band(a, b)) instead of &.
  • unpack, loadstring, setfenv — 5.1 names; 5.2+ uses table.unpack, load, and _ENV.
  • <const> and <close> — 5.4 only.

Lua 5.4 attributes

local MAX <const> = 100
print(MAX)

local function open(name)
  return setmetatable({name = name}, {__close = function(r) print("closing " .. r.name) end})
end

do
  local res <close> = open("db connection")
  print("using " .. res.name)
end
print("after block")
100
using db connection
closing db connection
after block

<const> forbids reassignment (checked at compile time); <close> calls the value's __close metamethod when the variable goes out of scope — even on errors.

Luau in brief

Roblox's Luau adds optional types and conveniences:

--!strict
local function greet(name: string, times: number?): string
    local count = times or 1
    local result = ""
    for i = 1, count do
        result ..= `Hello, {name}! `
    end
    return result
end

Everything in this course applies to Luau, apart from 5.3+ features like integer division and <close>.