Quirrel4.41.0

callee

Global, available without an import
callee(): function

Returns the closure that is currently running.

Return value

The closure of the function callee() was called from. This works for a native closure too.

Errors

Throws no closure in the calls stack when there is no enclosing closure. This cannot happen from script code: even the top level of a script runs inside a closure, so callee() there returns that closure rather than throwing.

Notes

Useful for a closure that calls itself without being bound to a name yet, such as one still being built as a table value or a default argument.

Example

examples/globals/callee.nut
let fact = function(n) {
  return n <= 1 ? 1 : n * callee()(n - 1)  // recurse without giving the closure a name
}
println("fact(5) =", fact(5))

// even the top level of a script runs inside a closure, so this never throws here
println("type(callee()) =", type(callee()))
Output:
fact(5) = 120
type(callee()) = function

See also

arrayCreates an array of size elements, each set to default_value.
assertThrows an error when condition is false.
compilestringCompiles source into a callable closure, without running it.
deduplicate_objectWalks obj and merges equal tables and arrays it finds inside.
errorWrites its arguments to the error stream.
errorlnWrites its arguments to the error stream, followed by a newline.
freezeReturns a reference to obj with the immutable flag set.
getconsttableReturns the const table.
globalsmodule index