Quirrel4.41.0

types.Thread.getstackinfos

Method on every thread
thread.getstackinfos(level: number): any

Returns call stack information from inside a suspended thread, for the given stack level of that thread (not of the caller).

The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing ... from the prose below, not from the signature.
examples/types/thread/getstackinfos-basic.nut
function sentryDuty() { suspend() }
let watchpost = newthread(sentryDuty)
watchpost.call()
println("watchpost.getstackinfos(0).func =", watchpost.getstackinfos(0).func)
Output:
watchpost.getstackinfos(0).func = sentryDuty

Parameters

levelnumberhow many frames up from the thread's current point to look

Return value

A table with these keys, or null when level is out of range:

Notes

Level 0 here is the thread's own innermost active frame - wherever it is currently suspended - and 1 is whatever called that, and so on. This differs from debug.getstackinfos, whose level 0 is the call to debug.getstackinfos itself: there is no such frame here, because the call happens from a different thread than the one being inspected.

Calling this on a thread that has never run ("idle"), or with a negative level, returns null rather than throwing.

Example

examples/types/thread/getstackinfos.nut
function inner() { suspend() }
function body() { inner() }
let t = newthread(body)
t.call()
println("t.getstackinfos(0).func =", t.getstackinfos(0).func)
println("t.getstackinfos(1).func =", t.getstackinfos(1).func)
println("t.getstackinfos(99) =", t.getstackinfos(99)) // out of range level
Output:
t.getstackinfos(0).func = inner
t.getstackinfos(1).func = body
t.getstackinfos(99) = null

See also

getstatusReturns the thread's current state as a string.
getstackinfosReturns call stack information for the given stack level
threadclass index