Matthew Wiggins wrote:
I was tring to use ncurses in a pascal program. and I defined a packed record of the WINDOW type, but how do I import the stdscr etc etc so I can use the functions?
The simple answer is var StdScr : asmname 'stdscr' WINDOW; but please read on...
I guess some people have done it. I'm not sure...
Yes, I've done it (when writing a BP compatible CRT unit), and the way I did it was via a C layer. So I made a file crtc.c which #include's <ncurses.h> and defines some routines on top of that. These routines are declared as "C;" in crt.pas (the Pascal unit). Some other routines in crt.pas are implemented in Pascal, but they only call the routines from crtc.c, not directly those from ncurses.
The reason why I did it this way is because that guarantees some portability. E.g., the WINDOW type might change in different releases of ncurses, or in different curses libraries. -- In fact, there is a library called PDCurses which is widely ncurses compatible, but, not surprisingly, the internal structure of its WINDOW type is quite different. In the CRT unit, however, I can just drop in PDCurses for ncurses, and it works, because the only routines that need to know about the internals (and if only about the size of the WINDOW type) are written in C and can read the ncurses.h header.
Of course, the better solution, as I pointed out in some other mails to this list, would be an automatic C header to Pascal translator which is quite a difficult thing to write. Anyone wants to try?
-- Frank Heckenbach, frank@fjf.gnu.de http://fjf.gnu.de/ PGP and GPG keys: http://fjf.gnu.de/plan