Thomas E Enebo wrote:
Exposing arguments is a great idea and it will be pretty simple to
implement. We could use it to give nicer warnings since we would know
if the signature could not properly dispatch to the underlying Ruby
signature.
Right now it goes on method arity, not supporting negative
(optional/rest) arities. So it could at least match up 1:1. But I think
we want to support optional/rest arities working too.
signature :foo, [String, int, int] => String
*In an earlier conversation I suggested using a hash for signature
specification, but I retract that since the flexibility will not buy
very much if we accept that the above syntax will always generate all
possible Java overloads. This seems like a reasonable expectation.
We could be more elaborate and specify less than all possible Java
signatures for a Ruby method, but if someone wants to do that they can
make a more restricted ruby method expressly for that purpose.*
def foo(a, b=4, c=5)
end
This would generate:
public String foo(String a) {...}
public String foo(String a, int b) {
IRubyObject rb = JavaToRuby(4);
...
}
public String foo(String a, int b, int c) {
IRubyObject rb = JavaToRuby(4);
IRubyObject rc = JavaToRuby(5);
...
}
Actually I think all three would just dispatch to the Ruby foo here,
since it can accept all three combinations of arguments.
Another question will be how to handle more elaborate defaults
signature :foo, [Bar] => int
def foo(a=Bar.foo)
if (a == null)
IRubyObject ra = TC.getConstant("Bar").callMethod("foo")
else
IRubyObject ra = JI.wrap(a)
end
end
Cases:
Bar => IRubyObject (regular Ruby object)
Bar => an existing Java class org.com.Bar
Bar => A Ruby object which has not been compile2'd yet <-- circular
issues if Bar has a method which accepts the class that this signature
is for.
As above, if we just dispatch with the args straight in, it should work
fine. The Ruby side handles all the defaults, and the Java side just
exposes all arities.
- Charlie
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email