On Thursday, 14 December 2017 at 13:56:28 UTC, mrphobby wrote:
After thinking about it for a while I guess it could work with one static dispatch method that maps selectors to specific instance methods. So when callbacks are made from Objective-C they are made to this one static method, which would then call the right method on the class.

I was playing with this myself based on Jacob's code and made it look like this:

extern (Objective-C) interface ViewController : NSViewController {
        extern (C)
        @ObjCMethodOverride("loadView")
        static void loadView(ViewController self, SEL sel) {
                printf("loadView\n");
        }

        extern (C)
        @ObjCMethodOverride("viewDidLoad")
        static void viewDidLoad(ViewController self, SEL sel) {
                printf("viewDidLoad\n");
        }

        ViewController init() @selector("init");
        mixin RegisterObjCClass;
}



so the mixin does some registering based on the method override attrs. It is still static with self cuz I actually felt hiding that made things a bit worse (inheritance wouldn't work like you expect), but most the registration stuff is now pulled from the attribute metadata.


Of course, my goal here isn't actually to do all of obj-c... just enough to port my simpledisplay.d. So I'm not sure if I'll make this public yet or just leave it as private and/or undocumented inside my library file.

Reply via email to