Some guidance on writing a Deimos C library interface

Jacob Carlborg doob at me.com
Sat Jul 14 10:16:28 PDT 2012


On 2012-07-14 05:24, Jens Mueller wrote:
> Hi,
>
> there is some documentation on writing a Deimos interface.
> E.g.
> http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP12
> http://dlang.org/interfaceToC.html
>
> I'd like to get a list of rules that one has to follow.
>
> First you have to convert the name of the header file to a valid D
> module name. Therefore, I found/came up with the following rules:
> * a slash (/) has to be replaced by a dot (.)
> * a dash (-) has to be replaced by a dot (.)
> * a D keyword gets a underscore (_) appended
>
> Maybe someone can commented on them. I suppose there are even more.
> These are just the ones I encountered.
>
> Some questions on module names I could not find a definite answer for:
> 1. The D page says they should be lower case. Should Deimos module names
>     also be made lower case?
> 2. Should all interfaces be put in a common package, say deimos?
>
> Translating the header file itself is pretty straightforward following
> http://dlang.org/interfaceToC.html. Though some cases are not covered:
> * E.g. use core.stdc.stdint for standard C types.

I would say that when a C typedef has a corresponding type in D, use 
that instead of an alias. For example:

int8_t -> use byte
int32_t -> use int

But one need to make sure that the typedef resolves to the same D type 
on all platforms.

> * const T* should be replaced with const(T)*
> * How to deal with macros?
>
> Can we write a recipe like guide for writing a Deimos interface?

You can have a look at dstep for automatically translate C/Objective-C 
headers: https://github.com/jacob-carlborg/dstep

-- 
/Jacob Carlborg




More information about the Digitalmars-d mailing list