ImportC + metaprogramming?
Steven Schveighoffer
schveiguy at gmail.com
Sun Jan 16 16:36:52 UTC 2022
On 1/16/22 3:13 AM, Walter Bright wrote:
> In this PR,
>
> https://github.com/dlang/druntime/pull/3670
>
> I added the ability for an ImportC file to import a D file. The initial
> purpose was so that core.stdc.stdarg could be imported to support
> variadics in C, without reimplementing them.
>
> I realized that this actually works - ImportC code can call D code! even
> use D templates!
Interesting!
>
> So then I got to thinking "what the hell have I unleashed?"
>
> I think I just destroyed dtoh.
Hm..., how does this help with preprocessor defines?
What I'm looking for is a way to write a .c (or .cm or whatever) file
that does:
```c
#include "mylib.h"
// rewrite mylib #defines as enums here
...
```
For use with ImportC.
And I don't know how to do that. There's no introspection capabilities
because the preprocessor isn't part of the D toolchain. Even doing it in
C is nearly impossible without renaming the thing. You can't use mixin
facilities, so using a D import doesn't work (plus it needs explicit
template parameters, which isn't valid C syntax).
Do you have a plan for this?
-Steve
More information about the Digitalmars-d
mailing list