Method calls with variable unnamed arguments after the pseudo-hash part of the selector
I'm playing again with implementing the Hillegass book in MacRuby, and ran across this method: + (NSAlert *)alertWithMessageText:(NSString *)messageTitle defaultButton:(NSString *)defaultButtonTitle alternateButton:(NSString *)alternateButtonTitle otherButton:(NSString *)otherButtonTitle informativeTextWithFormat:(NSString *)informativeText, ... (http://bit.ly/d1JIeQ) Now, the interesting part here is the ", ..." at the end. It takes variable arguments at the end that work as formatting arguments for informativeText, eg. sprintf(informativeText, ...). In MacRuby, this is invalid syntax: NSAlert.alertWithMessageText("Delete?", defaultButton:"Delete", alternateButton:"Cancel", otherButton:nil, informativeTextWithFormat:"delete %d people?", employees.count) Surely, in this case it can be worked around with: NSAlert.alertWithMessageText("Delete?", defaultButton:"Delete", alternateButton:"Cancel", otherButton:nil, informativeTextWithFormat:"delete #{employees.count} people?") And I can also call it as: NSAlert.send( :"alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat:", "Delete?", "Delete", "Cancel", nil, "delete %@ people?", employees.count) but I was wondering if this is a known limitation in MacRuby's method call syntax. So, is it known? Is there a plan to do anything about it?
On 10 Oct 2010, at 19:46, Caio Chassot wrote:
I'm playing again with implementing the Hillegass book in MacRuby, and ran across this method:
+ (NSAlert *)alertWithMessageText:(NSString *)messageTitle defaultButton:(NSString *)defaultButtonTitle alternateButton:(NSString *)alternateButtonTitle otherButton:(NSString *)otherButtonTitle informativeTextWithFormat:(NSString *)informativeText, ...
Now, the interesting part here is the ", ..." at the end. It takes variable arguments at the end that work as formatting arguments for informativeText, eg. sprintf(informativeText, ...).
Does it work if you pass an array in as the last argument? That's my assumption upon encountering it and trying to use it. C --- Caius Durling caius@caius.name +44 (0) 7960 268 100 http://caius.name/
On 2010-10-10, at 15:53 , Caius Durling wrote:
Now, the interesting part here is the ", ..." at the end. It takes variable arguments at the end that work as formatting arguments for informativeText, eg. sprintf(informativeText, ...).
Does it work if you pass an array in as the last argument? That's my assumption upon encountering it and trying to use it.
Do you mean: … informativeTextWithFormat:"… %d", [1] or … informativeTextWithFormat:["… %d", 1] Either way, it doesn't work, and if it did, it would have ambiguous interpretations. Mind it that my original example causes a parsing error during file load. I guess there's no special parsing for Objective-C-style method calls, it just parses as a method call with a trailing hash argument, and decides if this is a Objective-C-style method call during runtime.
Hi Caio, You seem to have found a bug in the parser :) Could you file that as a ticket? Thanks, Laurent On Oct 10, 2010, at 11:46 AM, Caio Chassot wrote:
I'm playing again with implementing the Hillegass book in MacRuby, and ran across this method:
+ (NSAlert *)alertWithMessageText:(NSString *)messageTitle defaultButton:(NSString *)defaultButtonTitle alternateButton:(NSString *)alternateButtonTitle otherButton:(NSString *)otherButtonTitle informativeTextWithFormat:(NSString *)informativeText, ...
Now, the interesting part here is the ", ..." at the end. It takes variable arguments at the end that work as formatting arguments for informativeText, eg. sprintf(informativeText, ...).
In MacRuby, this is invalid syntax:
NSAlert.alertWithMessageText("Delete?", defaultButton:"Delete", alternateButton:"Cancel", otherButton:nil, informativeTextWithFormat:"delete %d people?", employees.count)
Surely, in this case it can be worked around with:
NSAlert.alertWithMessageText("Delete?", defaultButton:"Delete", alternateButton:"Cancel", otherButton:nil, informativeTextWithFormat:"delete #{employees.count} people?")
And I can also call it as:
NSAlert.send( :"alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat:", "Delete?", "Delete", "Cancel", nil, "delete %@ people?", employees.count)
but I was wondering if this is a known limitation in MacRuby's method call syntax.
So, is it known? Is there a plan to do anything about it?
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On 2010-10-10, at 17:23 , Laurent Sansonetti wrote:
You seem to have found a bug in the parser :)
It seems I'm getting good at it ;)
Could you file that as a ticket?
participants (3)
-
Caio Chassot
-
Caius Durling
-
Laurent Sansonetti