Syntax
local settings <const> = { retries = 3 }Examples
Lua 5.4 const locals
Run with standalone Lua 5.4: lua example.lua. These scripts target Lua 5.4 rather than Roblox Luau.
local settings <const> = {retries = 3}
settings.retries = 4
print(settings.retries)
-- settings = {} -- compile error: assigning a const variable- Output: 4. The table remains mutable; uncommenting reassignment causes a compilation error.
Best practices
- Use const for binding invariants rather than deep immutability. Mark Lua 5.4 requirements when sharing scripts.
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