Why using wrappers for D?

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Oct 3 05:15:10 PDT 2016


On 04/10/2016 1:08 AM, Chalix wrote:
> 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 :)

Ok lets get a few things straight.

To use any kind of function you must declare it, plain and simple.
Any c or c++ function/class is the very much same way.
Now C++ types such as classes are highly limited in D since it doesn't 
ugh cross over all that well (it does some weird things).

These kinds of declarations are called bindings. We must have them since 
the D compilers don't support reading header files. Why don't they 
"just" support them you ask? Well simple, that's a whole new frontend 
that we must support... Walter is quite opposed to the idea and rightly so.

So the real interesting question, why do we have wrappers around e.g. 
c++ libs? Simple, the original C++ code was designed for C++ and we can 
simply do those interfaces better.

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the Digitalmars-d-learn mailing list