Why using wrappers for D?

Chalix via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Oct 3 05:08:54 PDT 2016


Hi All!

The documentation of D 
(https://dlang.org/overview.html#compatibility) says:

"Direct Access to C API's

Not only does D have data types that correspond to C types, it 
provides direct access to C functions. There is no need to write 
wrapper functions, parameter swizzlers, nor code to copy 
aggregate members one by one."


So, if there is no need for wrapper functions, why are there a 
lot of them? For example, GTK+ is a C library, with C-include 
files. Now there exists the GtkD (http://gtkd.org/) library, 
which describes itself as a wrapper of GTK+. GtkD contains the .d 
files (which I need for import, of course) and a seperate library 
(libgtkd-3.so).
If D has direct Access to C API's, why do we need this the gtkd-3 
lib, and not just use the gtk-3 lib?

Furthermore, if there is an not very popular C library, where no 
wrapper function exists, would it possible to include it into a D 
project? Probably I have to transform all the .h to .d files, so 
i can "import" them instead of "include" them. But then, could I 
link against the C-library?


I did not understand the concept of interaction between C and D, 
and I am a bit confused about wrapper functions and bindings for 
D now...
Would be great if someone could make it a bit more clear to me :)


More information about the Digitalmars-d-learn mailing list