Does D have a way to get and pass sturct information at runtime?
rempas
rempas at tutanota.com
Mon Jun 16 13:50:26 UTC 2025
On Monday, 16 June 2025 at 08:41:57 UTC, Dmitry Olshansky wrote:
> On Monday, 16 June 2025 at 07:30:31 UTC, rempas wrote:
>> So, I wanted to create a library to allow D to be used a
>> scripting language, in order to allow it to be used to
>> configure programs. Now, the design of everything is rather
>> simple. However, I do have one problem. Is there a way to pass
>> runtime information of a struct, to the compiler that will
>> compile my code?
>
> If what you desire is run-time configuration then the path
> forward is to invoke compiler say via std.process and compile
> your config to shared object. After that if compile is
> successful dlopen + dlsym is the way to go.
>
>> If what I want to do is not possible, I guess that another
>> idea would be to get compile time information about a struct,
>> write it to another file and automatically have the compiler
>> add that file (if that's even possible)? Or maybe, modify the
>> script file to add an **import** statement to it. Any ideas?
>
> There is import(“some_file”) to import files as data, but I’m
> not sure if that is what you are looking for.
Thanks for all that, they are all very interesting! Dejan Lekic
told me about "rdmd" and I think it might actually be what I'm
looking for. If it ends up been what I wanted, I guess I can
build an sort of "wrapper" type of library around it, to make it
a little easier to use and automate some things. I'll try it
later when I find the time, and I'll let you all know!
More information about the Digitalmars-d-learn
mailing list