Debug

getconstant

Reads a constant from a function, stack level, or prototype by one-based index.

Syntax

getconstant(target: function | integer, index: number | integer): any | nil
Aliases debug.getconstant

Arguments

NameTypeDescription
targetfunction | integerFunction, stack level, or prototype to inspect.
indexnumber | integerOne-based index inside constants, protos, upvalues, or stack slots.

Returns

NameTypeDescription
constantany | nilConstant value at the requested index, or nil when it is missing.

Description

Reads a constant from a function, stack level, or prototype by one-based index.

Call it with 2 parameter(s): target, index. The argument table explains which values are required and which ones only refine the behavior.

It returns constant (any | nil). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Example call with placeholder values.

local result = getconstant(1, 1)
print(result)