types.Class.getarity
Method on every
classReturns the argument counts of the class's _call metamethod, the same way function.getarity does for a plain function.
Return value
null if the class defines no _call metamethod. Otherwise a table with num_params, num_required and varargs, as function.getarity describes. The counts include the environment parameter that _call declares first.
Notes
Use getarity when only the counts are necessary, as it does not make the full introspection table.
Example
class Plain { x = 1 }
println("Plain.getarity() =", Plain.getarity())
class Scaler {
function _call(_env, value, factor = 2) { return value * factor }
}
let { num_params, num_required, varargs } = Scaler.getarity()
println($"Scaler: num_params={num_params} num_required={num_required} varargs={varargs}")
println("Scaler()(5) =", Scaler()(5))Output:
Plain.getarity() = null
Scaler: num_params=3 num_required=2 varargs=false
Scaler()(5) = 10See also
getfuncinfos | Describes the class's _call metamethod, the same way function.getfuncinfos describes a plain function. |
getarity | Returns the argument counts of this instance's 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. |
| class | class index |