Compiler patch for runtime reflection

Jacob Carlborg doob at me.com
Sat Oct 22 05:09:50 PDT 2011


On 2011-10-21 21:07, Vladimir Panteleev wrote:
> Hi,
>
> Igor Stepanov has created a patch for DMD and Druntime which adds RTTI
> information for class and struct members.
>
> Example:
>
> import std.stdio;
>
> class Foo
> {
> static void PrintHello()
> {
> writeln("Hello");
> }
> }
> void main()
> {
> auto info = cast(OffsetTypeInfo_StaticMethod)Foo.classinfo.m_offTi[0];
> assert(info.name == "PrintHello");
> auto print = cast(void function())info.pointer;
> print(); //prints "Hello"
> }
>
> While the inclusion of such functionality into the language remains a
> disputed matter, would anyone be interested in an unofficial patch for
> this?
>
> Walter: would it be okay if the compiler changes were published as a
> GitHub fork, or should we stick to patches?
>

Very cool.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list