digitalmars.D.announce - Runtime reflection
- Jascha Wetzel (7/7) Sep 18 2007 Here is a simple way of adding __traits based runtime reflection to D
- Ingo Oeser (9/11) Sep 18 2007 Wow! If that works, it is really a piece of art!
- Jascha Wetzel (14/24) Sep 19 2007 i have updated the file.
- Craig Black (6/30) Sep 19 2007 Impressive! I am surprised at how little code is required.
- Jascha Wetzel (16/21) Sep 20 2007 __traits does distinguish overloaded functions. But it does not
- dennis luehring (4/14) Sep 20 2007 do you see way to extend your lib with the ability
- Jascha Wetzel (4/20) Sep 21 2007 atm, i don't see a way. the current classinfoex version adds all members...
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.
Sep 18 2007
Jascha Wetzel wrote:Here is a simple way of adding __traits based runtime reflection to D classes:Wow! If that works, it is really a piece of art! - small, efficient - has constant runtime cost (speed AND size) - classes which don't want to be reflectable don't pay the cost - implementation is simple and obvious Best Regards Ingo Oeser
Sep 18 2007
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);
Sep 19 2007
"Jascha Wetzel" <firstname mainia.de> wrote in message news:fcrrk4$pb7$1 digitalmars.com...Jascha Wetzel wrote: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?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);
Sep 19 2007
Craig Black wrote: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?__traits does distinguish overloaded functions. But it does not associate functions that override an inherited function with the class they're implemented in. That is, there appears to be no way to list all functions that are implemented by the given class (overridden inherited or not) without also listing all inherited ones. derivedMembers only lists non-overridden functions. Another, maybe related thing is, that there appears to be no way to tell whether a function has an implementation or not. classinfoex tries to get the address of any function it finds in the static constructor, which will lead to linker errors (no body => no address). Otherwise, __traits is fine. classinfoex isn't using __traits very exhaustively, though. All it does is saving a TypeInfo with the name and address/offset of the symbol. The rest is drawn from TypeInfos. TypeInfo is more trouble. working around the missing parameter TIs in TypeInfo_Function is pretty extensive, and classinfoex is buggy there.
Sep 20 2007
Jascha Wetzel schrieb: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.do you see way to extend your lib with the ability to "see" the derivation-hierachy? ciao dennis
Sep 20 2007
dennis luehring wrote:Jascha Wetzel schrieb:atm, i don't see a way. the current classinfoex version adds all members to a class' reflection data. that way it's enough to add "mixin Reflect;" to a derived class.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.do you see way to extend your lib with the ability to "see" the derivation-hierachy? ciao dennis
Sep 21 2007