RE: Wrapping C++ libraries (was RE: Future of Euphoria)

new topic     » topic index » view thread      » older message » newer message

> -----Original Message-----
> From: Ray Smith [mailto:smithr at ix.net.au]

> I haven't looked at the problem for a few months so I'm a little 
> rusty.
> 
> I think the basic problem is that the OO way of doing things is 
> to sub class all of the objects and create classes that fit your 
> particualr application.
> 
> eg. to create a form ...
> 
> 1.  subclass a form object and create a new instance.
> 
> 2.  The form "initialise" method sets properties for this class and 
> then subclasses any controls it requires for this particular form.
> 
> 3.  The "sub classed" controls "initialise" method set the properties
> required for this control.

Right.  It helps to understand what, exactly, something like C++ does with
classes at the binary level (turns out to be the same thing COM does).  Each
class has a vtbl, or a virtual function table.  Which is to say, its an
array of pointers in memory.  The pointers are to the functions in the
class.  An instance of the class will basically be a pointer to the vtbl.
This pointer is AKA the 'this' pointer.  The this pointer is automatically
the first param passed to any function in the class.  C++ does this
automatically--Eu must do this explicitly.  Also, there's no built in way to
call functions by pointer in Eu (unless there are no params to be passed).
But I've figured that out, too :).
 
> 
> As a said it's been awhile since I looked at it.
> 
> I highly suspect my lack of C++ and FOXGUI knowledge is the main 
> problem.
> 
> I have "thought" about attempting to create a similiar structure of
> the initialise methods with Euphoria callbacks ... but I haven't 
> really thought through the details.
> 
> Basically ... how to change the structure of a highly OO'ed GUI 
> library with a message map to a simple ... create, set properties and
> process events module like win32lib.

Really not too difficult, once you grasp the above.  I think the most
difficult part of wrapping would be figuring out the name decorations, but
then, I've never really studied C++ name decoration, so it might not be as
bad as all that.  If you saw Derek's v56 of win32lib, you'd have seen one
way to modularize win32lib by controls, making it really quite OO.

To wrap an arbitrary OO lib, where you have a lot of 'overlap' within
classes (a la a GUI lib), I'd probably create a table of
methods/properties/whatever, with pointers to the appropriate places.  Then,
when something was called, via a handle/this pointer/whatever sort of id you
wanted, the wrapper would look up the appropriate pointer and call the
function.

The framework should all be there in EuCOM to do this.

Matt Lewis

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu