feat: add arity getter to Fn class and rename numParams to arity
Add a public `arity` getter to the Fn class that returns the number of required arguments for a function. Internally rename the `numParams` field to `arity` across the codebase for consistency, update the C API parameter name from `numParams` to `arity` in `wrenDefineMethod` and `wrenDefineStaticMethod`, and adjust the error message in `callFunction` to use the new field name. Also update documentation to clarify that extra arguments are ignored rather than causing an error, and add a new test file `test/function/arity.wren` verifying arity values from 0 to 4.
This commit is contained in:
@@ -18,6 +18,14 @@ you create a "bare" function when you don't want to immediately pass it as a
|
||||
|
||||
It is a runtime error if `block` is not a function.
|
||||
|
||||
### **arity**
|
||||
|
||||
The number of arguments the function requires.
|
||||
|
||||
:::dart
|
||||
IO.print(new Fn {}.arity) // 0.
|
||||
IO.print(new Fn {|a, b, c| a }.arity) // 3.
|
||||
|
||||
### **call**(args...)
|
||||
|
||||
**TODO**
|
||||
|
||||
@@ -115,8 +115,8 @@ Here we're passing a function to `greet` that takes two parameters, `first` and
|
||||
}
|
||||
}
|
||||
|
||||
It's an error to call a function with fewer or more arguments than its
|
||||
parameter list expects.
|
||||
It's an error to call a function with fewer arguments than its parameter list
|
||||
expects. If you pass too *many* arguments, the extras are ignored.
|
||||
|
||||
## Returning values
|
||||
|
||||
|
||||
Reference in New Issue
Block a user