Quirrel4.41.0

debug.getstackinfos

Defined in module "debug"
from "debug" import getstackinfos
getstackinfos(level: int): table|null

Returns call stack information for the given stack level

examples/debug/getstackinfos-basic.nut
from "debug" import getstackinfos

function inner() {
  let info = getstackinfos(1)   // 1 = the caller of getstackinfos itself
  println("info.func =", info.func)
}
inner()
Output:
info.func = inner

Parameters

levelinthow many frames up from this call to look

Return value

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

Level 0 is this call to getstackinfos itself; 1 is whatever called it, 2 is that function's own caller, and so on.

Notes

locals includes every name the VM tracks for that frame, including internal ones such as this and vargv; it is not filtered the way getlocals filters by default.

Example

examples/debug/getstackinfos.nut
from "debug" import getstackinfos

function inner(x) {
  println("level 0 func:", getstackinfos(0).func) // getstackinfos itself
  let si1 = getstackinfos(1)
  println("level 1 func:", si1.func)               // inner, our caller
  println("\"x\" in si1.locals =", "x" in si1.locals)
}

inner(5)
println("getstackinfos(100) =", getstackinfos(100)) // no such level
Output:
level 0 func: getstackinfos
level 1 func: inner
"x" in si1.locals = true
getstackinfos(100) = null

See also

getlocalsReturns a table of local variables at the given stack level
format_call_stack_stringReturns a formatted string describing the current call stack
debugmodule index