D on the Objective-C runtime?

Jacob Carlborg doob at me.com
Sun Sep 6 11:52:12 PDT 2009


On 9/6/09 15:12, Michel Fortin wrote:
> On 2009-09-06 08:32:43 -0400, Christopher Wright <dhasenan at gmail.com> said:
>
>> Off topic, but this would be a good place for user-defined attributes.
>> Then you could write something like:
>>
>> @IBAction void openWindow(Object sender) {}
>
> Indeed... although IBAction isn't so bad as a mixin, it gets much worse
> with ObjcMethod where it is necessary to list all the argument types to
> allow resolving overloaded functions:
>
> void doOneAndTwo(int i, int j) {}
>
> mixin ObjcMethod(void, doOneAndTwo, "doOne:andTwo:", int, int);

That is actually not necessary. It would be sufficient with a template 
taking an alias to the method (most of the times). Then you can build a 
selector string out of the method name and the parameter names. To get 
the types of the method you can use traits templates/functions available 
both in phobos and tango. You would probably also need a template taking 
an alias and a selector string when the above doesn't work.

This would work best with new methods when you can control the method 
and parameter names and not with existing methods.

> Compare to what could be done with a parametrized attribute:
>
> @ObjcMethod("doOne:andTwo:") void doOneAndTwo(int i, int j);
>
> That'd would be a lot more convenient, especially with interfaces for
> which none of the mixin above can work (they insert some static struct
> member to store the "attributes").
>
>




More information about the Digitalmars-d mailing list