mono / Embeddinator-4000

Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
MIT License
758 stars 95 forks source link

[objc] Managed to native callbacks #217

Open spouliot opened 7 years ago

spouliot commented 7 years ago

Right now we can only make native consume managed API but there's no two way integration. E.g.

rolfbjarne commented 7 years ago

I'm not sure it's possible to implement virtual methods without some kind of runtime support:

public class A {
    public virtual int X () { return 0; }
    public static void ShowX (A a) { Console.WriteLine (a.X ()); }
}
public class B : A {
    public override int X () {  return 1; }
}
@interface C : B
-(int) X;
@end
@implementation C
{
-(int) X {
    return 2;
}
int main ()
{
    C *c = [[C alloc] init];
    [A showX: c]; // this prints 1, even though C overrides X to return 2.
}
spouliot commented 7 years ago

yeah, I'm not even sure if we want to go that deep - that's more than just embedding. Sadly it remains non-obvious from a library consumption point of view (which might not know about the embeddinator)

rolfbjarne commented 7 years ago

Maybe we should add comments that says that methods shouldn't be overridden: https://softwareengineering.stackexchange.com/a/183706?

spouliot commented 7 years ago

Not ideal but, like your link mention, it's ObjC after all :)

There's quite a few more things we should auto-comment in the headers. Having a @warning on each (with a link to our docs to explain why) sounds like a reasonable approach.