Does D have a way to get and pass sturct information at runtime?

Dmitry Olshansky dmitry.olsh at gmail.com
Mon Jun 16 08:41:57 UTC 2025


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.





More information about the Digitalmars-d-learn mailing list