Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, after about 8 hours of digging through this crap I have determined that it is indeed possible to call C functions natively.</p> <p>HOWEVER, it is also stated that "It would be senseless to attempt to port to D or write D wrappers for the vast array of C APIs available. How much easier it is to just call them directly."</p> <p>Yeah, I'm going to call BS on that one. You DO have to port to D. Is it not considered porting when you are going from a macro enabled preprocessing .h file to a .d file? It is definitely nontrivial. So in my opinion they are intentionally leaving out the hard part and trying to make it look way better than it actually is.</p> <p>In case anyone is wondering, If you have a C api that you would like to call in your D code: go grab the header file and attempt to convert it to something that D can read. Then simply compile your code, importing your new .d file, and linking it with whatever you are interfacing with. If you did it right, it'll work and you'll now have lots of memory leaks.</p> <p>In my opinion, unless you need the entire library, save yourself a headache and just link a small C wrapper to your D code. You grab only what you need, and you have the added benefit of being able to rename stuff to whatever you want.</p> <p>There are a couple of projects to help automate the process of translating header files. dtoh for windows only, and bcd which is found on dsource. bcd also includes bindings for curses! they are listed as being alpha only, but they seem to be working. I'm trying to call their curses.d file from my main.d file and I've been getting:</p> <pre><code>main.d:13: Error: cannot implicitly convert expression ("ype any character to see it in bold\x0a") of type string to char[] main.d:15: Error: function aphrodite.curses.printw (char*,...) is not callable using argument types (char[]) main.d:15: Error: cannot implicitly convert expression (stuff) of type char[] to char* main.d:20: Error: function aphrodite.curses.printw (char*,...) is not callable using argument types (string) main.d:20: Error: cannot implicitly convert expression ("F1 Key pressed") of type string to char* main.d:26: Error: function aphrodite.curses.printw (char*,...) is not callable using argument types (string) main.d:26: Error: cannot implicitly convert expression ("The pressed key is ") of type string to char* main.d:28: Error: function aphrodite.curses.printw (char*,...) is not callable using argument types (string,int) main.d:28: Error: cannot implicitly convert expression ("%c") of type string to char* </code></pre> <p>so my problem lies in the way C handles strings and the way D handles strings. They don't match up and my extremely limited C knowledge doesn't tell me how to fix it. Luckily, for all the anti-documentation about calling C functions, there is quite a bit of info about how D types translate to C types.</p> <p>I sincerely hope that someone finds this helpful somewhere down the line.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload