Quirrel4.53.0

types.Instance.getarity

Method on every instance
nodiscard instance.getarity(): any

Returns 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

examples/types/instance/getarity.nut
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") = true

See also

getfuncinfosDescribes this instance's class's _call metamethod, the same way function.getfuncinfos describes a plain function.
getarityReturns the argument counts of the class's _call metamethod, the same way function.getarity does for a plain function.
getarityReturns how many arguments the closure takes: the counts that getfuncinfos gives, without the names, defaults and type masks it collects.
instanceclass index