types.Instance.getarity
Method on every
instanceReturns the argument counts of this instance's class's _call metamethod, the same way function.getarity does for a plain function.
Return value
null if the instance's class defines no _call metamethod, so the instance cannot be called like a function. Otherwise the counts of the _call closure, its environment parameter included, as function.getarity describes.
Notes
Equivalent to getclass().getarity(). The counts come from the _call closure, not from a getfuncinfos method that the class defines.
Example
class Plain { x = 1 }
println("Plain().getarity() =", Plain().getarity())
class Blaster {
function _call(_env, target, power = 1) { return target != null && power > 0 }
}
let { num_params, num_required, varargs } = Blaster().getarity()
println($"Blaster(): num_params={num_params} num_required={num_required} varargs={varargs}")
println("Blaster()(\"tank\") =", Blaster()("tank"))Output:
Plain().getarity() = null
Blaster(): num_params=3 num_required=2 varargs=false
Blaster()("tank") = trueSee also
getfuncinfos | Describes this instance's class's _call metamethod, the same way function.getfuncinfos describes a plain function. |
getarity | Returns the argument counts of the class's _call metamethod, the same way function.getarity does for a plain function. |
getarity | Returns how many arguments the closure takes: the counts that getfuncinfos gives, without the names, defaults and type masks it collects. |
| instance | class index |