debug
Provides functions to collect and modify information of the Luau callstack and Luau functions.
Functions
getupvaluecount
debug.
getupvaluecount
(
fnOrIndex:
number
|
(
T...
)
→
U...
--
The function or call-stack index to get the number of up-values.
) →
number
--
The number of up-values this function/ stack index holds.
Gets the number of up-values/ up-references of the given function or call-stack index fnOrIndex
.
Errors
Type | Description |
---|---|
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
getconstantcount
debug.
getconstantcount
(
fnOrIndex:
number
|
(
T...
)
→
U...
--
The function or call-stack index to get the number of constants.
) →
number
--
The number of constants this function/ stack index holds.
Gets the number of constants of the luau function or call-stack index fnOrIndex
.
C closures
C closures do not have constants.
Errors
Type | Description |
---|---|
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
getconstants
debug.
getconstants
(
fnOrIndex:
number
|
(
T...
)
→
U...
--
The function or call-stack index to get all constants.
) →
{
any
}
--
All constants this function/ stack index holds.
Gets all of the constants of the luau function or call-stack index fnOrIndex
.
C closures
C closures do not have constants.
Errors
Type | Description |
---|---|
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
getconstant
debug.
getconstant
(
fnOrIndex:
number
|
(
T...
)
→
U...
,
--
The function or call-stack index to get.
index:
number
--
The numerical index of the constant to get.
) →
any
--
The constant at the given index.
Gets the constant of the luau function or call-stack index fnOrIndex
at the given constant index
.
C closures
C closures do not have constants.
Errors
Type | Description |
---|---|
invalid constant index | The index must be non-negative, more than 0 and smaller than the number of constants the closure has. Use debug.getconstantcount to get the number of constants before calling this function. |
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
setconstant
debug.
setconstant
(
fnOrIndex:
number
|
(
T...
)
→
U...
,
--
The function or call-stack index to set.
index:
number
,
--
The numerical index of the constant to set.
newValue:
any
--
The new constant to set.
) →
(
)
Sets the constant of the luau function or call-stack index fnOrIndex
at the given constant index
to newValue
.
Vector objects
Luau can have Vector objects as constants. Due to this, you must set the extra
field on the lua_TValue
structure correctly!
C closures
C closures do not have constants.
Errors
Type | Description |
---|---|
the type of the new value that of the original | Whatever is at index index does not match with the type of newValue. For userdatas, their tags must also match. |
invalid constant index | The index must be non-negative, more than 0 and smaller than the number of constants the closure has. Use debug.getconstantcount to get the number of constants before calling this function. |
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
getupvalues
debug.
getupvalues
(
fnOrIndex:
number
|
(
T...
)
→
U...
--
The function or call-stack index to get all up-values/ up-references.
) →
{
any
}
--
All up-values/up-reference this function/ stack index holds.
Gets all of the up-value/ up-references of the given function or call-stack index fnOrIndex
.
C closures
You must NEVER allow the mutation of the up-values of C closures! C closures are specific on their constraints.
Errors
Type | Description |
---|---|
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
getupvalue
debug.
getupvalue
(
fnOrIndex:
number
|
(
T...
)
→
U...
,
--
The function or call-stack index to get.
upIndex:
number
--
The numerical index of the up-reference/up-value to get.
) →
any
--
The up-reference/up-value at the given index.
Gets the up-value or up-reference of the given function or call-stack index fnOrIndex
at the given up-reference/up-value index
.
C closures
You must NEVER allow the mutation of the up-values of C closures! C closures are specific on their constraints.
Errors
Type | Description |
---|---|
invalid upvalue index | The index must be non-negative, more than 0 and smaller than the number of upvalues the closure has. Use debug.getupvaluecount to get the number of upvalues before calling this function. |
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
setupvalue
debug.
setupvalue
(
fnOrIndex:
number
|
(
T...
)
→
U...
,
--
The function or call-stack index to set.
upIndex:
number
,
--
The numerical index of the up-reference/up-value to set.
newValue:
any
--
The new up-reference/up-value to set.
) →
(
)
Sets the up-value or up-reference of the given function or call-stack index fnOrIndex
at the given up-reference/up-value index
to value
.
C closures
You must NEVER allow the mutation of the up-values of C closures! C closures are specific on their constraints.
Errors
Type | Description |
---|---|
the type of the new value that of the original | Whatever is at index upIndex does not match with the type of newValue. For userdatas, their tags must also match. |
invalid upvalue index | The index must be non-negative, more than 0 and smaller than the number of upvalues the closure has. Use debug.getupvaluecount to get the number of upvalues before calling this function. |
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
setstack
debug.
setstack
(
level:
number
,
--
The level to set.
stackIndex:
number
,
--
The numerical index in the stack to set.
newStackElement:
any
--
The new stack element to set.
) →
(
)
Sets the stack element at index stackIndex
at call-stack level level
to newStackElement
.
C closures
You must NEVER allow the mutation of the stacks of C closures! This is related to vulnerabilities.
Errors
Type | Description |
---|---|
the type of the new value that of the original | Whatever is at element stackIndex does not match with the type of newStackElement. For userdatas, their tags must also match. |
invalid stack index | The index must be non-negative, more than 0 and smaller than the size of the stack. Use debug.getstackcount to get the number of upvalues before calling this function. |
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
getstack
debug.
getstack
(
level:
number
,
--
The level to get.
stackIndex:
number?
--
The numerical index in the stack to get, or nil to get the entire stack.
) →
any
|
{
any
}
--
The stack element at the given index, or the entire stack.
Returns the stack element at index stackIndex
at call-stack level level
.
If no stackIndex
is provided, the entire stack will be returned.
Errors
Type | Description |
---|---|
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
getstackcount
debug.
getstackcount
(
level:
number
--
The level to get.
) →
number
--
The number of elements on the luau stack.
Returns the number of elements on the luau stack at the provided call-stack level
.
Errors
Type | Description |
---|---|
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |
validlevel
debug.
validlevel
(
level:
number
--
The level to check.
) →
boolean
--
If true, the level is valid and can be used on call functions.
Returns if the given call-stack level is a valid level.
traceback
debug.
traceback
(
threadOrMessage:
string
|
thread
,
--
The first line of the returned string.
levelOrMessage:
number
|
string
,
--
The number of calls "up" the call stack to return.
level:
number?
) →
string
--
The traceback up to the given level from the current function.
identical to debug.traceback
Function Behaviour
This function skips over C closures.
info
debug.
info
(
levelOrThreadOrFunction:
number
|
thread
|
(
T...
)
→
U...
,
--
The level/ function to get the information from. Or, optionally, the thread to get the information from.
whatOrLevelOrFunction:
number
|
string
|
(
T...
)
→
U...
,
--
The information to get, or the level/ function to get the information from.
what:
string?
--
The information to get (if the thread is provided as first argument).
) →
K...
|
nil
--
Information on the order of 'what', may be nil.
Identical to debug.info
getinfo
debug.
getinfo
(
level:
number
|
(
T...
)
→
U...
--
The level/ function to get the information from.
) →
DebugInfo
--
The information about the function that is currently using the given stack frame or of a given function.
Returns information about the function that is currently using the given stack frame or of a given function.
Errors
Type | Description |
---|---|
level out of range | The provided stack level was out of range. use debug.validlevel to check if the level is valid before calling this function. |