help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] Re: ncurses "objectification": first approximation


From: Paolo Bonzini
Subject: [Help-smalltalk] Re: ncurses "objectification": first approximation
Date: Sat, 28 Oct 2006 00:11:42 +0900
User-agent: Thunderbird 1.5.0.7 (Macintosh/20060909)

Brad Watson wrote:
I'm considering splitting the wrapped c function calls across two subclasses of 
CObject: NCWindow and NCScreen.  c functions that return a WINDOW pointer, or 
take a WINDOW  pointer argument will be wrapped
by an instance method in the NCWindow class.  c functions that return a SCREEN pointer, 
or take a SCREEN pointer argument will be wrapped by an instance method  in the NCSreen 
class.  The remaining c functions will by wrapped by class methods in the class that they 
have the closest affinity.   Does this scheme sound reasonable, and consisent with the 
goal of "objectification" NCurses ?

SCREEN functions are a bit of a pain to wrap, because NCurses uses a FILE * while Smalltalk only knows file descriptors (and rightly so). Therefore, since they are just three (newterm, set_term, delscreen) and rarely used, I'd just do without them completely. For the record, though, newterm (and possibly initscr/endwin/isendwin/slk_init and other listed in the curs_initscr(3X) man page) could be an NCScreen class method.

I think that NCurses functions without a WINDOW * are divided in three: those that are merely wrappers (e.g. refresh () for wrefresh (stdscr)), those that return a WINDOW *, and those that do something else.

The first need not be wrapped at all, IMO. Object-oriented people are used to singleton and will happily write NCWindow stdscr wprintw: 'foo'. There may be some exception (e.g. I can't see a difference between getch and wgetch), but it is not worthwhile introducing exception IMO

The second should undoubtedly be NCWindow class methods. You can make them return an NCWindow instance using "returning: NCWindow type" in the C call-out.

The third category includes initscr, endwin, and so on. As I said, these could be placed in a separate NCScreen class, where they would be class methods (or instance methods if the class implemented the Singleton pattern). But if you want, it's also possible to put them in NCWindow as class methods, as you prefer.

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]