Re: Class info on interfaces

2015-08-29 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-08-28 22:40, rumbu wrote: The linkage check it's good as long you don't have an abomination like this: extern(C++) interface CPPInterface { extern(D) void foo(); } Good point. Anyway, the problem is the availability of such function. If the interface doesn't contain any

Re: Class info on interfaces

2015-08-28 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-08-26 20:59, Adam D. Ruppe wrote: Yes, exactly. COM and C++ things won't necessarily have a D TypeInfo available and since interfaces can be them, it can't be sure. What I do there is to just cast the interface to Object. Then you should check for null to cover those cases, then you

Re: Class info on interfaces

2015-08-28 Thread rumbu via Digitalmars-d-learn
On Friday, 28 August 2015 at 06:19:55 UTC, Jacob Carlborg wrote: On 2015-08-26 20:59, Adam D. Ruppe wrote: Yes, exactly. COM and C++ things won't necessarily have a D TypeInfo available and since interfaces can be them, it can't be sure. What I do there is to just cast the interface to

Re: Class info on interfaces

2015-08-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 28 August 2015 at 06:19:55 UTC, Jacob Carlborg wrote: Is it possible to detect at compile time if an interface is not a native D interface? Not fully, no, but you might be able to reflect into the methods and see what kind of linkage they have.

Re: Class info on interfaces

2015-08-28 Thread rumbu via Digitalmars-d-learn
On Friday, 28 August 2015 at 19:36:37 UTC, Jacob Carlborg wrote: On 2015-08-28 17:41, rumbu wrote: I don't know about Objective-C, but: - for native D interfaces __traits(getVirtualIndex, NativeInterface.firstFunction) == 1 since the first entry in vtbl is the contained object - for C++

Re: Class info on interfaces

2015-08-28 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-08-28 16:31, Adam D. Ruppe wrote: Not fully, no, but you might be able to reflect into the methods and see what kind of linkage they have. http://dlang.org/phobos/std_traits.html#functionLinkage That might work. However, you can't do anything with an interface that isn't in there

Re: Class info on interfaces

2015-08-28 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-08-28 17:41, rumbu wrote: I don't know about Objective-C, but: - for native D interfaces __traits(getVirtualIndex, NativeInterface.firstFunction) == 1 since the first entry in vtbl is the contained object - for C++ interfaces __traits(getVirtualIndex, CPPInterface.firstFunction) == 0 -

Class info on interfaces

2015-08-26 Thread Jacob Carlborg via Digitalmars-d-learn
I noticed the calling classinfo on an interface returns the class info of the static type and not the dynamic type. Is that intentional? Perhaps because of COM and C++ interfaces? module main; import std.stdio; interface Foo {} class Bar : Foo {} void main() { Foo f = new Bar;

Re: Class info on interfaces

2015-08-26 Thread Ali Çehreli via Digitalmars-d-learn
On 08/26/2015 11:59 AM, Adam D. Ruppe wrote: On Wednesday, 26 August 2015 at 18:53:19 UTC, Jacob Carlborg wrote: Is that intentional? Perhaps because of COM and C++ interfaces? Yes, exactly. COM and C++ things won't necessarily have a D TypeInfo available and since interfaces can be them, it

Re: Class info on interfaces

2015-08-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 26 August 2015 at 18:53:19 UTC, Jacob Carlborg wrote: Is that intentional? Perhaps because of COM and C++ interfaces? Yes, exactly. COM and C++ things won't necessarily have a D TypeInfo available and since interfaces can be them, it can't be sure. What I do there is to just