ncurses "objectification": first approximation -- was Re: Re: newt library bindings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ncurses "objectification": first approximation -- was Re: Re: newt library bindings

Brad Watson
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 ?

Thanks,

Brad Watson



----- Original Message ----
From: Paolo Bonzini <[hidden email]>
To: Brad Watson <[hidden email]>; GNU Smalltalk <[hidden email]>
Sent: Thursday, October 26, 2006 9:16:29 PM
Subject: Re: [Help-smalltalk] Re: newt library bindings


> mvwaddch: aPoint ch: aChar
>     ^self mvaddchPrimitive: (aPoint y) x: (aPoint x) ch: aChar!
>  
No need for the "Primitive" part.  (And if aPoint is not the first
parameter, BTW, I'd call its keyword "at: aPoint")
> mvwaddchPrimitive: anInt1 x: anInt2 ch: aChar
>     <cCall: 'mvaddch' returning: #int args: #(#self #int #int #char )>!
>  
Likewise, and you are actually calling mvwaddch of course.

Otherwise good.  Don't be afraid to post this kind of question publicly.

Paolo







_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: ncurses "objectification": first approximation

Paolo Bonzini
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


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk