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:
Bob Nystrom
2015-01-24 04:33:05 +00:00
parent c65b03ac32
commit 368d9a3052
7 changed files with 46 additions and 28 deletions
+5
View File
@@ -0,0 +1,5 @@
IO.print(new Fn {}.arity) // expect: 0
IO.print(new Fn {|a| a}.arity) // expect: 1
IO.print(new Fn {|a, b| a}.arity) // expect: 2
IO.print(new Fn {|a, b, c| a}.arity) // expect: 3
IO.print(new Fn {|a, b, c, d| a}.arity) // expect: 4