newLISP Fan Club

Forum => newLISP in the real world => Topic started by: TedWalther on August 07, 2015, 02:26:03 PM

Title: importing variadic functions? (ncurses module)
Post by: TedWalther on August 07, 2015, 02:26:03 PM
I wanted to make a text mode app with newlisp.  I start to make an ncurses module so I can use ncurses.  Right away I find this function has a variable number of arguments.  What is the right way to import and use these?


Quote
       int printw(const char *fmt, ...);

       int wprintw(WINDOW *win, const char *fmt, ...);

       int mvprintw(int y, int x, const char *fmt, ...);

       int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...);

       int vwprintw(WINDOW *win, const char *fmt, va_list varglist);

       int vw_printw(WINDOW *win, const char *fmt, va_list varglist);


My first guess failed:


Quote
(import LIB_NCURSES "printw" "int" "void*")

(printw "abc %d %d %d" 1 2 3)

=> ERR: mismatch in number of arguments


How to do variadic functions using libffi?  Is it possible?  If this is a feature to be added, could we have "..." to specify variadic function?



And yes, it did work with the old cdecl style of import.  Then I lose the benefit of type checking. Oh well.