How to get to a class initializer through introspection?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Aug 3 00:37:48 UTC 2020
On 8/2/20 7:59 PM, 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.
Holy Molly this works. FWIW here's what I plan to use:
https://run.dlang.io/is/A6cbal. No need for __gshared because immutable
stuff is already shared.
The only bummer is it can't be read during compilation, but I assume
there'd be a chicken and egg problem if it were.
Thanks, Adam! Walter and I had absolutely no idea this can be done but
we thought to post here on the off chance. Thanks again!
More information about the Digitalmars-d
mailing list