debug.getstackinfos
Returns call stack information for the given stack level
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 = innerParameters
level | int | how many frames up from this call to look |
Return value
A table with these keys, or null when level is out of range:
func- the name of the function at that levelsrc- its source fileline- the line currently executing in itlocals- a table of its local variables, keyed by name
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
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 levelOutput:
level 0 func: getstackinfos
level 1 func: inner
"x" in si1.locals = true
getstackinfos(100) = nullSee also
getlocals | Returns a table of local variables at the given stack level |
format_call_stack_string | Returns a formatted string describing the current call stack |
| debug | module index |