[Gambas-devel] ncurses component

Benoît Minisini gambas at ...1...
Sun Apr 1 21:13:52 CEST 2012


Le 28/03/2012 23:21, tobi a écrit :
>
>
> i'm already probing with that very Window class, but had a slightly different approach just because i
> don't know of the old basic syntaxes (the funning thing i thought of was mirroring parts of the
> gb.qt4/gb.gtk Windows to ncurses), i'll take a look on the basic syntaxes soon, it's kind of general
> knowledge... maybe as soon as i'll create an account on sourceforge... (the most probably tomorrow, sorry)
> i tried to figure out something like the inheritance of a Stream but i lacked knowledge of internal
> stream behaviour, i.e. if i could overwrite whatever is used to process incoming data.
>
> regards,
> tobi
>

As an example of how to implement a stream class, you can look at the 
Socket class in the gb.net sources ('CSocket.h' & 'CSocket.c' files).

In a few words:


(1) You must declare your object structure that way:

typedef
   struct {
     GB_BASE ob;
     GB_STREAM stream;
     ...
   }
   MYCLASS;


(2) You must declare a structure that represents all stream methods:

GB_STREAM_DESC MyClassStream =
{
   open: MyClassStream_open,
   close: MyClassStream_close,
   read: MyClassStream_read,
   write: MyClassStream_write,
   seek: MyClassStream_seek,
   tell: MyClassStream_tell,
   flush: MyClassStream_flush,
   eof: MyClassStream_eof,
   lof: MyClassStream_lof,
   handle: MyClassStream_handle
};

Each stream method must have a specific declaration, as specified in the 
GB_STREAM_DESC declaration in 'gambas.h'


(3) When you open the stream (in your case it should be as soon as the 
object is created, inside the constructor), you must initialize your 
object with the previous structure:

#define THIS ((MYCLASS *)_object)

BEGIN_METHOD_VOID(MyClass_new)

   ...
   THIS->stream.desc = &MyClassStream;

END_METHOD


I hope that things are clearer now.

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list