www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Deimos rules?

reply Xavier Bigand <flamaros.xavier gmail.com> writes:
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?
Nov 13 2013
next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Nov 13 2013
parent "qznc" <qznc web.de> writes:
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.
Nov 14 2013
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
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
Nov 14 2013
next sibling parent Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
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?
Nov 14 2013
prev sibling next sibling parent Xavier Bigand <flamaros.xavier gmail.com> writes:
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.
Nov 14 2013
prev sibling parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
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
Nov 14 2013
parent Jacob Carlborg <doob me.com> writes:
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
Nov 15 2013
prev sibling parent Xavier Bigand <flamaros.xavier gmail.com> writes:
Le 13/11/2013 23:01, Xavier Bigand a écrit :
 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 think it's enough mature to be integrated to deimos. It builds fine but I have some issues with XCB, the official sample written in C doesn't work too, so the bindings seems correct. You can fork it from : https://github.com/D-Quick/XCB
Dec 01 2013