debug.getconstant

Reads one function constant.

Syntax

Signature
debug.getconstant(FunctionOrLevel: function | number, Index: number) -> any

Aliases

This function has no aliases.

Parameters

ParameterTypeDescription
FunctionOrLevelfunction | numberLuau closure or positive stack level.
IndexnumberOne-based constant slot.

Returns

TypeDescription
anyThe constant at Index.

Notes

Indexes start at 1. Nil, table, and function constants are returned as nil. An invalid index raises an error.

Example

Luau
local Function = function() local Message = "Hello" return Message end
local Result = debug.getconstant(Function, 1)
print(Result)