D and reflection

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Wed May 7 12:42:17 PDT 2014


On 2014-05-07 18:51, amehat wrote:
> Hello everyone,
>
> I'm working on porting a java library in D, and I stuck on a class
> because it works with the reflection.
>
>  From what I've read on prowiki
> (http://www.prowiki.org/wiki4d/wiki.cgi?LanguagesVersusD), D can not do
> reflection, it is limited to the Run-Time Type Information (RTTI )
> (http://dlang.org/traits.html).
>
> Here is the piece of code that blocks me:
>
> static {
>          Class clazz = this.class;
>
>          auto accessible2Args = new Callback(clazz, "accessibleProc", 2);
>          auto proc2Args = accessible2Args.getAddress();
>          if (proc2Args === 0) {
>          (...)
>      }
> (...)
> }
>
> I am looking for a workaround that I have not found yet.
> If someone an idea on the subject, I'm interested.
>
> Thank you to you.

It depends on how the rest of the code looks like. If you're lucky you 
can just take the address of "accessibleProc". You need to either 
provide more code or you can have a look at DWT [1], which is port of 
the Java library SWT. It actually contains code exactly like that. Have 
a look at this Java file [2] and the translation do D [3]. I'm using a 
static method here, it's not certain the same will work for you.

[1] https://github.com/d-widget-toolkit/dwt-mac

[2] 
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/bundles/org.eclipse.swt/Eclipse%20SWT%20Accessibility/cocoa/org/eclipse/swt/accessibility/SWTAccessibleDelegate.java?id=v3550

[3] 
https://github.com/d-widget-toolkit/dwt-mac/blob/master/dwt/accessibility/SWTAccessibleDelegate.d

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list