debug.validlevel Synchronous

  • debug.isvalidlevel
  • isvalidlevel
  • validlevel

Check whether a stack level exists before inspecting it. This is useful in tracing code where callers may have different depths.

Syntax
Luau
debug.validlevel(level: any, targetThread: thread?) -> boolean

Parameters

Function parameters
ParameterTypeDescription
levelanyStack depth to test.
targetThreadthread?Optional coroutine whose stack should be checked.

Returns

boolean

true if that level is valid; false for a missing or invalid level.

Example

Example
Luau
local function inspect()
    if debug.validlevel(1) then
        print(debug.getinfo(1).source)
    end
end
inspect()
Kawaii documentation