On 2011-10-19 11:24, J Arrizza wrote:
Just noticed an odd thing when I was trying Jacob's code.
This works great:
auto x = new someClass();
Object o = x;
void delegate() dg;
foreach(i, m; __traits(derivedMembers, someClass))
{
writeln("i=", i, " m=", m);
if(m != "__ctor")
{
dg.funcptr = cast(void function()) o.classinfo.vtbl[i + 6];
dg.ptr = cast(void*) o;
dg();
}
}
but this doesn't (it segfaults):
Object o = Object.factory("someClass");
void delegate() dg;
foreach(i, m; __traits(derivedMembers, someClass))
{
writeln("i=", i, " m=", m);
if(m != "__ctor")
{
dg.funcptr = cast(void function()) o.classinfo.vtbl[i + 6];
dg.ptr = cast(void*) o;
dg();
}
}
Is the object returned by Object.factory() not the same somehow as the
one returned by new()?
John
For Object.factory you need the fully qualified name, i.e.
SomeClass.classinfo.name. If Object.factory can't find a class name it
will just return null.
--
/Jacob Carlborg