debug.getconstant
C closures are not supported
This function will throw an error if called on a C closure, such as print
, since C closures have no accessible constants.
debug.getconstant
returns the constant at the specified index from a Luau function. If no constant exists at that index, it returns nil
instead.
This is useful when you want to inspect specific constant values (such as strings, numbers, or booleans) without dumping the entire list.
function debug.getconstant(func: (...any) -> (...any) | number, index: number): number | string | boolean | nil
Parameters
Parameter | Description |
---|---|
func |
The Lua function (or stack level) whose constant to retrieve. |
index |
The position of the desired constant. |
Examples
Example 1
Getting a valid constant | |
---|---|
Example 2
Getting an out-of-range constant | |
---|---|
Example 3
Calling on a C closure should error | |
---|---|