Am 07.05.2014 18:51, schrieb amehat:
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.

D can do reflection, but only at compile time.

If you can use the class name directly, a possibility might be something like:

import std.traits;
import std.stdio;

class test
{
        void accessibleProc () {}
}

void main ()
{
        auto t = new test();
        alias MemberFunctionsTuple!(test, "accessibleProc") accessible2Args;
    if (accessible2Args.length == 1)
        {
                // accessibleProc address in accessible2Args[0]
        }
}

If not, it is better if someone with more experience can step in.

--
Paulo

Reply via email to