debug. validlevel Synchronous
debug.isvalidlevelisvalidlevelvalidlevel
Check whether a stack level exists before inspecting it. This is useful in tracing code where callers may have different depths.
Luau
debug.validlevel(level: any, targetThread: thread?) -> booleanParameters
| Parameter | Type | Description |
|---|---|---|
level | any | Stack depth to test. |
targetThread | thread? | Optional coroutine whose stack should be checked. |
Returns
booleantrue if that level is valid; false for a missing or invalid level.
Example
Luau
local function inspect()
if debug.validlevel(1) then
print(debug.getinfo(1).source)
end
end
inspect()