Returns the constant table of a Luau function - every literal and global name the compiler stored in its bytecode.
When Roblox’s LVM builds a function, it stores every literal that function uses - strings, numbers and booleans - plus the name of every global it calls, in a constant table attached to that function. debug.getconstants returns that whole table.
Hand it a function and you get that function’s constants. Hand it a number instead and that number is read as a stack level. Level 0 is the call you are in, 1 is the one that called it, and the lookup runs on whichever function sits at that level.
Its counterpart debug.getconstant returns a single slot by index. Only Luau functions have a constant table, so check the target with islclosure first - a C closure like print has none and the call fails.
Most commonly used while reversing a game - to see what a ModuleScript or a LocalScript closure holds inside its bytecode without decompiling it.
Parameters
Returns
{boolean | nil | number | string} - a table of the function’s constants. Each one sits at a numbered slot from the compiled bytecode.
A constant table belongs to one function. If you passed a number instead of a function, it belongs to whichever function is running that many calls up from where you called this. The table can have gaps, so iterate over it with pairs and not ipairs.
Aliases
Example
This returns all literal values referenced inside the compiled function.