Thread overview
Deimos rules?
Nov 13, 2013
Xavier Bigand
Nov 13, 2013
Jonathan M Davis
Nov 14, 2013
qznc
Nov 14, 2013
Jacob Carlborg
Nov 14, 2013
Xavier Bigand
Nov 15, 2013
Jonathan M Davis
Nov 15, 2013
Jacob Carlborg
November 13, 2013
I work on XCB integration, so I think that I can add bindings in deimos.

C headers are translated to d modules by using DStep or manually?
If manually need I respect some syntactical rules?
November 13, 2013
On Wednesday, November 13, 2013 23:01:58 Xavier Bigand wrote:
> I work on XCB integration, so I think that I can add bindings in deimos.
> 
> C headers are translated to d modules by using DStep or manually? If manually need I respect some syntactical rules?

It's completely project-dependent. Deimos is for D bindings to C libraries. They need to be the extern(C) declarations which correspond to the C header declarations without any D wrappers. Beyond that, how the project is put together or how the bindings are generated is really up to whoever does the header translation. DStep is new enough that I expect that most of Deimos has been converted by hand. There's also htod on Windows, but it does a pretty poor job, because it's D1-compatible (e.g. it doesn't handle const right).

So, you can translate the headers however you want, and there are no syntactic rules. I'd say that you should follow the same file layout as the actual C headers (a one-to-one translation of header.h -> header.d), but how everything is formatted in those files doesn't really matter. It's up to you.

- Jonathan M Davis
November 14, 2013
On Wednesday, 13 November 2013 at 22:46:45 UTC, Jonathan M Davis wrote:
> On Wednesday, November 13, 2013 23:01:58 Xavier Bigand wrote:
>> I work on XCB integration, so I think that I can add bindings in deimos.
>> 
>> C headers are translated to d modules by using DStep or manually?
>> If manually need I respect some syntactical rules?
>
> It's completely project-dependent. Deimos is for D bindings to C libraries.
> They need to be the extern(C) declarations which correspond to the C header
> declarations without any D wrappers. Beyond that, how the project is put
> together or how the bindings are generated is really up to whoever does the
> header translation. DStep is new enough that I expect that most of Deimos has
> been converted by hand. There's also htod on Windows, but it does a pretty
> poor job, because it's D1-compatible (e.g. it doesn't handle const right).
>
> So, you can translate the headers however you want, and there are no syntactic
> rules. I'd say that you should follow the same file layout as the actual C
> headers (a one-to-one translation of header.h -> header.d), but how everything
> is formatted in those files doesn't really matter. It's up to you.

Ah, that reminds that the tutorial needs some good advice about this. As far as I know, DStep is the current state of art.

November 14, 2013
On 2013-11-13 23:01, Xavier Bigand wrote:
> I work on XCB integration, so I think that I can add bindings in deimos.
>
> C headers are translated to d modules by using DStep or manually?
> If manually need I respect some syntactical rules?

I would say stay as close to the original C code as possible. Although I do prefer to translate typedefs like int8_t to real D types, like byte, if they exist.

-- 
/Jacob Carlborg
November 14, 2013
On 14/11/13 13:13, Jacob Carlborg wrote:
> I would say stay as close to the original C code as possible. Although I do
> prefer to translate typedefs like int8_t to real D types, like byte, if they exist.

In some ways I wonder why D's types aren't just specified according to the number of bits -- int8, int16, int32, int64 instead of byte, short, int, long. I suppose on balance it's probably less readable and easier to make mistakes writing.

More generally -- is it considered desirable to provide not only the C-like translation, but also a higher-level "D-ified" wrapper?  Or is that considered overkill for Deimos?
November 14, 2013
Le 14/11/2013 13:13, Jacob Carlborg a écrit :
> On 2013-11-13 23:01, Xavier Bigand wrote:
>> I work on XCB integration, so I think that I can add bindings in deimos.
>>
>> C headers are translated to d modules by using DStep or manually?
>> If manually need I respect some syntactical rules?
>
> I would say stay as close to the original C code as possible. Although I
> do prefer to translate typedefs like int8_t to real D types, like byte,
> if they exist.
>
I started by changing extension of files from .h to .d, and translating in place everything. I take libX11 as model.

I'll certainly make a pull request when I will able to run a simple demo.

I let all originals comments as it during the translation.

November 15, 2013
On Thursday, November 14, 2013 15:06:59 Joseph Rushton Wakeling wrote:
> On 14/11/13 13:13, Jacob Carlborg wrote:
> > I would say stay as close to the original C code as possible. Although I
> > do
> > prefer to translate typedefs like int8_t to real D types, like byte, if
> > they exist.
> In some ways I wonder why D's types aren't just specified according to the number of bits -- int8, int16, int32, int64 instead of byte, short, int, long. I suppose on balance it's probably less readable and easier to make mistakes writing.

It's a stylistic choice, and Walter went with not putting the sizes in the type names. But since their sizes are still fixed, it doesn't really matter.

> More generally -- is it considered desirable to provide not only the C-like translation, but also a higher-level "D-ified" wrapper? Or is that considered overkill for Deimos?

Deimos is specifically for bindings to C libraries and _not_ for D-ified wrappers. And that's the stance that Walter has taken when it's come up. But with dub and code.dlang.org, it should be simple enough to put a D-ified wrapper in a place where folks can find it.

- Jonathan M Davis
November 15, 2013
On 2013-11-15 05:30, Jonathan M Davis wrote:

> Deimos is specifically for bindings to C libraries and _not_ for D-ified
> wrappers. And that's the stance that Walter has taken when it's come up. But
> with dub and code.dlang.org, it should be simple enough to put a D-ified
> wrapper in a place where folks can find it.

Personally I would mix the wrappers and bindings in the same project, as along as you could use the bindings completely separate without the wrappers.

-- 
/Jacob Carlborg