debug.getconstants
Returns a Lua function’s constant table.
Syntax
debug.getconstants(target: function | number) -> {any}
Also available as
getconstantsget_constants
Parameters
| Parameter | Type | Description |
|---|---|---|
target | function or number | Lua function or visible caller level. |
Returns
| Type | Description |
|---|---|
table | Constants keyed by their compiled index. |
Description
The keys are the compiler’s one-based constant indices. Nil slots can create holes, so the length operator and ipairs are not reliable ways to enumerate every index. Compilation and optimization can change constant order; do not assume that a particular source literal always receives the same index.
Example
local function sample() return "hello", 42 end
for index, value in debug.getconstants(sample) do
print(index, value)
end
These are Game executor contracts. Check build requirements and session lifetimes before using them.
