D and C APIs

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 12 03:05:38 PST 2016


On Tuesday, 12 January 2016 at 10:43:40 UTC, Russel Winder wrote:
> On Tue, 2016-01-12 at 08:12 +0000, Atila Neves via 
> Digitalmars-d wrote:
>> On Monday, 11 January 2016 at 17:25:26 UTC, Russel Winder 
>> wrote:
>> > I am guessing that people have an answer to this:
>> > 
>> > D making use of a C API needs a D module adapter. This can 
>> > either be constructed by hand (well it can, but…), or it can 
>> > be auto generated from the C header files and then hand 
>> > massaged (likely far better). I think the only tool for this 
>> > on Linux is DStep.
>> > 
>> > This is all very well for a static unchanging API, but what 
>> > about C APIs that are generated from elsewhere? This 
>> > requires constant update of the D modules. Do people just do 
>> > this by hand?
>> > 
>> > Is the pain of creating a V4L D module set worth the effort 
>> > rather than just suffering the pain of writing in C++?
>> 
>> This is the kind of thing I wrote reggae for. CMake is an 
>> alternative, but I'd rather write D than CMake script.
>
> CMake scripts are hideous in that the language is like nothing 
> else, other than perhaps m4 macros. They should have used Lisp. 
> Or Python.
>
> I must try Reggae at some stage, but for now I need to progress 
> this Me TV rewrite. D and Rust provide so many barriers to 
> effective use of a C library, that I am resorting to using C++. 
> Yes you have to do extra stuff to avoid writing C code, but 
> nowhere near the amount you have to to create D and Rust 
> adaptors.

What's so hard about writing a few function prototypes, aliases 
and enums? It's annoying that we have to do it, but compared to 
writing the rest of a project it's always going to be a tiny 
amount of work.

For a lot of projects you can only bind what you actually need, I 
often just pretend that I have already written the bindings then 
write whatever lines are necessary to get it to compile!



More information about the Digitalmars-d mailing list