Skip to main content
Returns one value from a Luau function’s constant table, picked by its bytecode index.
Every Luau function keeps a constant table in its compiled bytecode: the string, number and boolean literals it uses, and the names of the globals it calls. debug.getconstant returns the single entry at the index you ask for. The first argument is either the function itself or a stack level. A number is treated as a level - 0 is the call running right now, higher numbers walk up the callers - and the lookup then happens on whichever function is running there. Run debug.getconstants first to see the whole table and its indices, then come back here for the one you want. C closures have no constants, so confirm the target with islclosure before calling or it will error. Most commonly used to pull one known constant straight out of a script’s closure once debug.getconstants has shown you which index it sits at.

Parameters

Returns

boolean | nil | number | string - the single constant sitting at index in the target’s constant table. That value is whatever the compiler stored in that slot: a string or number literal, a boolean, or the name of a global the function calls.

Aliases

  • getconstant

Example

Constants include strings, numbers, and functions referenced in the function’s scope.