debug.get_function_info_table
"debug"from "debug" import get_function_info_tableReturns meta information about a function as table
Parameters
func | function | the function to inspect |
Return value
A table with these keys:
functionName- the function's namenative-truefor a native closure,falsefor a script closurerequiredArgs- how many arguments must be passed, not countingthisargNames- array of parameter namesargTypeMask- array of type masks, one per entry inargNames; pair one withtype_mask_to_stringto read itellipsisArgTypeMask- the type mask for a trailing...parameter, or0when the function does not take oneobjectTypeMask- the type mask accepted for the implicitthisreturnTypeMask- the declared return type maskpure,nodiscard,fastcall- the function's attributesdoc- the docstringdocwould return for the same function, ornull
Errors
func must already be a closure or a native closure; passing anything else fails the parameter type check before this function runs.
Notes
pure is true either because the function carries the [pure] attribute, or because the compiler proved the body has no side effect on its own, without any attribute written. fastcall is a native-only trait; a script closure never reports it.
A native bound through a type mask instead of a declaration string has no real parameter names, so argNames is filled with placeholders arg1, arg2, and so on. Most methods on the built-in types (array, string, ...) are bound this way, since they typecheck arguments with a mask rather than a parsed decl string.
When SQ_STORE_DOC_OBJECTS is disabled, native declaration text is not retained. Native functions then use the type-mask fallback, so declaration-only parameter names and the declared return type are not available.
Example
from "debug" import get_function_info_table
function add(a, b = 5) { return a + b }
let t = get_function_info_table(add)
println($"{t.functionName} native={t.native} requiredArgs={t.requiredArgs}")
println("t.argNames =", ", ".join(t.argNames))
// no attribute was written, but the compiler proved the body has no side effect
println($"pure={t.pure}")
// array.insert is bound with a type mask, not a decl string, so it has no real
// parameter names
println("get_function_info_table([].insert).argNames =", ", ".join(get_function_info_table([].insert).argNames))add native=false requiredArgs=1
t.argNames = a, b
pure=true
get_function_info_table([].insert).argNames = arg1, arg2See also
get_function_decl_string | Returns a function declaration string |
type_mask_to_string | Convert type mask to human-readable string |
doc | Returns a documentation string for a function, class, or instance |
| debug | module index |