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
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()) = functionSee also
array | Creates an array of size elements, each set to default_value. |
assert | Throws an error when condition is false. |
compilestring | Compiles source into a callable closure, without running it. |
deduplicate_object | Walks obj and merges equal tables and arrays it finds inside. |
error | Writes its arguments to the error stream. |
errorln | Writes its arguments to the error stream, followed by a newline. |
freeze | Returns a reference to obj with the immutable flag set. |
getconsttable | Returns the const table. |
| globals | module index |