5 Cent tip for today [ Ncurses ]

Featuring the Dragonfly web framework

5 Cent tip for today [ Ncurses ]

Postby newdep » Mon Mar 15, 2004 8:25 pm

;;;
;;; newlisp ncurses example
;;;

(set 'buffer "newlisp * ncurses How simple can it get :) press a key!")

;;; import functions from ncurses lib
(set 'ncfuncs '( "initscr" "box" "newwin" "endwin" "delwin" "wgetch" "wrefresh" "mvwprintw" ))
(define (import-ncurses) (dolist (x ncfuncs ) (import "/lib/libncurses.so.5" x)))

;;; Newlisp-Ncurses
(import-ncurses)
(initscr)
(set 'window (newwin 3 80 0 0 ))
(box window 0 0)
(mvwprintw window 1 1 buffer )
(wrefresh window)
(wgetch window)
(delwin window)
(endwin)

;;; exit
(exit)
-- (define? (Cornflakes))
newdep
 
Posts: 2019
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Postby newdep » Mon Mar 15, 2004 8:34 pm

Actualy what amazes me the most is that the return from the lib-call 'window
here is directly a pointer, the need for 'get-float 'get-integer is not needed :-)
Norman.
-- (define? (Cornflakes))
newdep
 
Posts: 2019
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Postby Lutz » Mon Mar 15, 2004 10:32 pm

Wonderful Norman, your ncurses example is amazing!

About 'get-integer', 'get-float' etc.: you only need those when the return value from your 'C' function is a pointer to those. As some of the curses functions take and return pointers you can receive and feed them back directly.

You can even retrieve structure members when structure pointers come back using those get-xxxx functions and adding offsets to the pointers (see mysql.lsp).

Lutz
Lutz
 
Posts: 5258
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby eddier » Fri May 14, 2004 8:21 pm

Ooooffff! I overlooked this one. Thanks Normann! This one WILL come in handy. I wonder how difficult it would be to make a newlisp editor in newlisp using ncurses?

Eddie
eddier
 
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Postby newdep » Sat May 15, 2004 4:46 pm

Hello Eddier,

Actualy i Tried once building an editor under linux, you have to be patient ;-)
Ncurses comes with lot of routines and the trick is to pick the right one... But it
should be possible there newlisp handles lib-calls very nicely...
-- (define? (Cornflakes))
newdep
 
Posts: 2019
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Re: 5 Cent tip for today [ Ncurses ]

Postby schilling.klaus » Thu Jul 05, 2012 6:54 am

How does the foreign function interface treat C-preprocessor macros? Some `functions' in the ncurses library, such as getyx, are really macros and would screw up for example the simple ffi of Clisp. (The backdoor is then to write wrapper code in C and link it against the Clisp library.)

Klaus Schilling
schilling.klaus
 
Posts: 7
Joined: Thu Jul 05, 2012 5:24 am

Re: 5 Cent tip for today [ Ncurses ]

Postby Lutz » Thu Jul 05, 2012 4:12 pm

Both FFI flavors in newLISP - the simple and the libffi based - will not import macros. But on the BSD manual page for getcurx on OSX its says "All of these interfaces are provided as macros and functions". But instead of getyx use getcurx and getcury on the ncurses lib.
Lutz
 
Posts: 5258
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California


Return to So, what can you actually DO with newLISP?

Who is online

Users browsing this forum: No registered users and 2 guests

cron