Quirrel4.41.0

debug.get_stack_top

Defined in module "debug"
from "debug" import get_stack_top
get_stack_top(): int

Returns the current VM stack top index

Return value

How many values are visible on this call's own frame: the implicit this, plus whatever explicit arguments it was called with.

Notes

This function takes no arguments of its own, so a legal call to it always returns 1, the implicit this; nothing about how deep the calling chain goes is visible from inside it. The stack this reports is always relative to the currently running call, never an absolute count from the bottom of the VM.

Example

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

println("get_stack_top() =", get_stack_top()) // always 1: just the implicit 'this'

function inner() {
  return get_stack_top() // still 1, regardless of how deep inner() is called from
}
println("inner() =", inner())

try {
  get_stack_top(42) // the signature takes no arguments
} catch (e) {
  println("get_stack_top(42) throws:", e)
}
Output:
get_stack_top() = 1
inner() = 1
get_stack_top(42) throws: wrong number of parameters passed to native closure 'get_stack_top' (2 passed, 1 required)

See also

format_call_stack_stringReturns a formatted string describing the current call stack
getstackinfosReturns call stack information for the given stack level
debugmodule index