types.Function.getfuncinfos
Method on every
functionReturns a table describing the closure: its name, parameters, and other introspection data the VM tracks for it.
Return value
A table with these keys:
native-truefor a native closure,falsefor a script closurepure,nodiscard,fastcall- the closure's attributesname- the closure's name, ornullif it was never given onefreevars- how many free variables it captured (seegetfreevar)src,line- source file and first line;nullfor a native closureparameters- an array of parameter names, starting with"this"defparams- default values, one per parameter that has onerequired_params- how many leading entries ofparameters(includingthis) have no defaultvarargs-truewhen the closure ends in...typecheck,return_type_mask,varargs_type_mask- type masks for the parameters, the return value, and the vararg tail; seedebug.type_mask_to_stringdoc- the docstring, ornullparamscheck- a native closure only: the raw registration countcallchecks against (seedebug.get_function_info_tablefor how it is turned into a plain required-argument count)
Notes
this is always parameters[0], so required_params and the length of parameters both count it; debug.get_function_info_table's requiredArgs and argNames do not, so f.getfuncinfos().required_params is one higher than get_function_info_table(f).requiredArgs for the same f.
Example
function add(a, b = 10) { return a + b }
let info = add.getfuncinfos()
println($"{info.name} required_params={info.required_params}")
println($"parameters={", ".join(info.parameters)}")
println($"varargs={info.varargs} native={info.native}")Output:
add required_params=2
parameters=this, a, b
varargs=false native=falseSee also
get_function_info_table | Returns meta information about a function as table |
getfreevar | Returns the name and current value of one of the closure's free variables (the outer locals it captured when it was created). |
| function | class index |