Runtime reflection

Craig Black craigblack2 at cox.net
Wed Sep 19 17:18:03 PDT 2007


"Jascha Wetzel" <firstname at mainia.de> wrote in message 
news:fcrrk4$pb7$1 at digitalmars.com...
> Jascha Wetzel wrote:
>> Here is a simple way of adding __traits based runtime reflection to D 
>> classes:
>>
>> http://mainia.de/classinfoex.d
>> (requires DMD 2.004)
>>
>> It does not increase the class instance size.
>> All extra info is stored statically.
>>
>> See the doc-comment for details.
>
> i have updated the file.
> dynamic calls are now supported:
>
> class A
> {
>     mixin Reflect;
>     int foo() { return 1234; }
>     void bar(string s) { writefln("%s", s); }
> }
>
> A o = new A;
> call(o, "bar", null, "argument string");
> Box retval;
> call(o, "foo", &retval);
> writefln("foo returned %s", retval);

Impressive!  I am surprised at how little code is required.

I remember something about traits not distinguishing between overloaded 
functions.  Is this still the case or was this fixed in 2.004?  Are there 
any other problems with traits that you have encountered? 




More information about the Digitalmars-d-announce mailing list