How to get to a class initializer through introspection?

Johan j at j.nl
Mon Aug 3 08:04:16 UTC 2020


On Sunday, 2 August 2020 at 23:59:23 UTC, Adam D. Ruppe wrote:
> On Sunday, 2 August 2020 at 22:25:19 UTC, Andrei Alexandrescu 
> wrote:
>> Any ideas on how to do that via introspection? The fields are 
>> accessible, but not their default values.
>
> It is ugly but possible right now to pull in the symbol via 
> extern(C).
>
> See line 20 in my latest blog's example:
>
> http://dpldocs.info/this-week-in-d/Blog.Posted_2020_07_27.html#zero-runtime-classes
>
> ldc complains but it is a type mismatch not a fundamental 
> barrier, I just didn't figure out the right thing to silence it 
> yet.
>
>> It seems like __traits(type, getInitializer) might be 
>> necessary.
>
> but yes this would be generally nicer anyway imo.

That for that post Adam, I've been trying the same thing lately.
It's needed to fix this: 
https://issues.dlang.org/show_bug.cgi?id=21097

https://github.com/weka-io/druntime/blob/9e5a36b0fcac242c4d160d3d7d0c85565aebe79f/src/core/internal/lifetime.d#L118

-Johan






More information about the Digitalmars-d mailing list