Oh My Gentool [v0.0.1] (Yet another binding generator)

evilrat evilrat666 at gmail.com
Sun Oct 28 01:34:32 UTC 2018


On Saturday, 27 October 2018 at 16:55:23 UTC, Atila Neves wrote:
> On Tuesday, 23 October 2018 at 20:32:29 UTC, Andrea Fontana 
> wrote:
>> On Tuesday, 23 October 2018 at 20:03:42 UTC, Atila Neves wrote:
>>> We do - it's just very far from being complete. dpp can do 
>>> some simple C++ and would have been able to do 
>>> C-with-classes-style C++ ages ago. My focus is on templates 
>>> though, since for me I can't see any useful C++ libraries 
>>> that I'd actually want to call from D that don't use 
>>> templates. And sometimes it's as silly as wanting to bind to 
>>> an existing not-that-complicated library that happens to have 
>>> a std::vector in its structs. For that, you need to be able 
>>> to translate the standard library.
>>
>> Interesting. I'm using it for many different c libraries but I 
>> didn't think it worked for c++  already!
>>
>> The only problem I found with DPP is that simple consts 
>> declared with #define are not translated if not explicitly 
>> used. I think i can understand the reason (macro evaluation, I 
>> guess) but it would be useful to have a way to export them if 
>> they are simple consts...
>
> The whole idea of dpp is to be able to use headers as they are 
> used in C and C++. Macros there don't exist unless they're 
> expanded, so it's the same thing with dpp.
>
> Maybe it's good idea to add a runtime flag to translate 
> non-function-like macros as enums... hmm.

My tool already does simple value-macro extraction, I also 
thinking about replacing macro with shortcut-to-self(see below) 
so in AST it will look like a function call, then the user can 
convert the macro itself to a template or mixin, so this way the 
code can be preserved more or less as-is. Though I don't have 
exact date or plan.

```
     #define REG_FN(A) gContext->reg(#A)
     ...

     // somewhere in code
     REG_FN(sum);
```

So in this trivial example REG_FN will be preserved in code as 
written. This way in more complex cases, such as whole class 
creation with macro, it should be possible to retain that 
information. But again this will require studying, it might sound 
useful in theory, however bindings is done for a specific 
conditions, and so whether it is really useful or not is an open 
question.




More information about the Digitalmars-d-announce mailing list