Syntax
getconstants(target: function | number): tableAliases
debug.getconstantsArguments
| Name | Type | Description |
|---|---|---|
target | function | number | Lua function or stack level whose constants are returned. |
Returns
| Name | Type | Description |
|---|---|---|
constants | table | Table keyed by one-based constant indices. Indices for nil, function, and table constants are absent. |
Description
Returns constants from a Lua function or stack level as a table keyed by one-based constant index. target must be a function or stack level number. Invalid stack levels raise "Level out of range". Non-function and non-number targets raise a type error expecting "function or number". C closures raise "Lua function expected". Nil, function, and table constants are absent from the returned table. debug.getconstants is an alias.
Call it with 1 parameter(s): target. The argument table explains which values are required and which ones only refine the behavior.
It returns constants (table). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Read the Proto constants table for a Lua closure.
local function target()
return "ready"
end
local constants = getconstants(target)
for index, value in pairs(constants) do
print(index, value)
end