Note that there are some explanatory texts on larger screens.

plurals
  1. POncurses api with the D Programming Language
    primarykey
    data
    text
    <p>I am trying to teach myself AI using neural networks. Long story short, I wanted to create a simple graphic that would display what is happening in my program using ncurses. The tutorial that I am using is found <a href="http://www.ai-junkie.com/ann/evolved/nnt1.html" rel="nofollow noreferrer">here</a>.</p> <p>I was under the impression that D was compatible with C and I could theoretically call C functions relatively easily.</p> <p>I find that not to be the case. I am a relatively novice programmer, so even the simplistic explanations are a little above my head. I found this <a href="http://www.digitalmars.com/d/2.0/interfaceToC.html" rel="nofollow noreferrer">here</a>.</p> <blockquote> <p>D is designed to fit comfortably with a C compiler for the target system. D makes up for not having its own VM by relying on the target environment's C runtime library. 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>This is done by matching the C compiler's data types, layouts, and function call/return sequences. </p> </blockquote> <p>That sounds wonderful. A little bit over my head. I tested and got a simple C program working:</p> <pre><code>#include &lt;curses.h&gt; int main(void) { int ch; initscr(); noecho(); cbreak(); printw("Hit Ctrl+C to exit ...\n\n"); for (;;) { ch = getch(); printw("Value of char: %d (%02x)\n", ch, ch); } endwin(); return 0; } </code></pre> <p>shamelessly copied and pasted from another question on SO. At least I did my homework.</p> <p>I tried basically the same thing from a simple D program. I got this error:</p> <pre><code>Error: module curses is in file 'curses.d' which cannot be read </code></pre> <p>I am absolutely positive that I am trying something really stupid.</p> <p>Is there an easy way to use ncurses in a D program?</p> <p>I'm running on zero sleep and caffeine, so please be gentle! Even a link to a website would be greatly appreciated!</p> <p>I probably didn't include everything that I should have, so AMA.</p> <p>And feel free to insult my intelligence.</p>
    singulars
    1. This table or related slice is empty.
    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. COOk, so there is my comment up there about how D should just be able to call C, and then again on the very same site, It's claimed that you will have to rewrite the .h files to be .d files. That is apparently a pretty big difference... I'm leaning towards the second, since there is a special windows tool that is supposed to help automate the process of translating the header files. htod it's called. Unfortunately it's windows only. I'm beginning to realize how fractured the D community really is...
      singulars
    2. COok, so it's possible to link D with a C library. Provided that you didn't happen to name functions the same. (it was main(). facepalm). the problem is, you still need to convert the header file... So technically it IS possible to call C functions 'easily' and without having to resort to a wrapper. But what they leave out is that you have to convert the .h file to a .d file since D does not implement the CPP. Great. Have you SEEN the .h file I want to convert? it is literally nothing but a thousand lines of #ifndefs and #Pragmas.
      singulars
    3. COI wouldn't say that the complication is hidden, it just isn't expressed more than needing to convert .h to .d, which those familiar with C know isn't going to be simple. And ncurses is pretty much a macro library as you probably noticed. You can run the CPP against a file and have it output the C which is much easier to convert, but still may not be correct. Anyway good work.
      singulars
 

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