DIP87: Enhanced Foreign-Language Binding
Anon via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jan 22 17:31:02 PST 2016
On Friday, 22 January 2016 at 16:37:31 UTC, Jacob Carlborg wrote:
> On 2016-01-21 05:21, Anon wrote:
>> Seeing the recent extern(C++) threads, and much concern
>> therein, I'd
>> like to propose DIP87: http://wiki.dlang.org/DIP87
>>
>> Destroy to your heart's content.
>
> * How do you plan to differentiate specifying the namespace
> compared with specifying the mangled name for an extern(C++)
> symbol?
Ideally, by whether the `extern()` forms a block or it is
attached directly to the symbol. I understand that wouldn't work
with existing implementation in the compiler, but hopefully it
wouldn't be too difficult to do. But I know nothing of compiler
internals so am probably wrong.
> * For Objective-C bindings one needs to be able to specify the
> mangled name for a class or interface without affecting the
> names of the methods. It's required because in Objective-C it's
> possible to have the same name for a class and a protocol
> (interface). In the Foundation framework (standard library)
> there are a class "Object" and a protocol "Object"
I'll have to look into this more. My cursory reading told me of
"instance" methods and "class" methods, that get mangled as
"_i_<Something>_<method>..." and "_c_<Something>_<method>..."
respectively. Is this what you are talking about?
> * When creating Objective-C bindings it's basically required to
> specify the selector for every method
I know, because of the parameter names being part of the API (and
mangled name). I still think the approach described in the DIP
should be workable.
> * In Objective-C the mangled name and the selector is not the
> same. The mangled name is for the linker to find the correct
> symbol. The selector is for finding the correct method
> implementation at runtime
Sure, but when using ObjC code from D:
extern(Objective-C) class Something {
void moveTo(float x, float y) @selector("x:y:");
}
// Elsewhere
something.moveTo(1,2);
I don't see how the selector is doing anything more than mangling
here. Even if you have multiple methods in D that mangle to the
method name in ObjC (minus parameters), that selection is done by
D, which then mangles the name according to the selector, right?
If not, do you have an example handy to illustrate?
More information about the Digitalmars-d
mailing list