On 2011-10-18 18:48, J Arrizza wrote:
I'm trying to write some sample code to:
   1 create an object via it's name
   2 search an object for it's functions
   3 call a static function in a class
   4 call a non-static function in an object

#1, #2 and #3 were straightforward. But  #4 looks like it's not possible
in DMD 2.0.

I found this:

http://www.digitalmars.com/d/archives/digitalmars/D/announce/Runtime_reflection_9949.html

which implies #4 is doable in Windows but not Linux. I'm using Linux
64-bit Ubuntu.

Any other avenues I can chase?

TIA,
John

How about doing something like this:

class Foo
{
    void bar ()
    {
        writeln("bar");
    }
}

void main ()
{
    auto foo = new Foo;

    auto members = __traits(derivedMembers, Foo);
    void delegate () dg;

    foreach (i, m ; members)
        if (m == "bar")
            dg.funcptr = cast(void function()) foo.classinfo.vtbl[i + 6];

    dg.ptr = cast(void*) foo;
    dg();
}



--
/Jacob Carlborg

Reply via email to