1. RE: Wrapping C++ libraries (was RE: Future of Euphoria)
- Posted by Matthew Lewis <matthewwalkerlewis at YAHOO.COM> Jun 03, 2002
- 428 views
> -----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
2. RE: Wrapping C++ libraries (was RE: Future of Euphoria)
- Posted by Derek Parnell <Derek.Parnell at SYD.RABOBANK.COM> Jun 03, 2002
- 435 views
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C20B46.7AF55570 charset=iso-8859-1 > -----Original Message----- > From: Matthew Lewis [mailto:matthewwalkerlewis at YAHOO.COM] > Sent: Tuesday, 4 June 2002 1:32 > To: EUforum > Subject: RE: Wrapping C++ libraries (was RE: Future of Euphoria) [big snip] > > > 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. Funny you should say this Matt, as this is very similar to how I'm planning to reorganise the win32lib. I'm experimenting with another (smaller) app now and the results are very pleasing. ------ Derek. ================================================================== De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht ontvangt wordt u verzocht de inhoud niet te gebruiken en de afzender direct te informeren door het bericht te retourneren. ================================================================== The information contained in this message may be confidential and is intended to be exclusively for the addressee. Should you receive this message unintentionally, please do not use the contents herein and notify the sender immediately by return e-mail. ================================================================== ------_=_NextPart_000_01C20B46.7AF55570 Content-Type: application/ms-tnef
3. RE: Wrapping C++ libraries (was RE: Future of Euphoria)
- Posted by Ray Smith <smithr at ix.net.au> Jun 03, 2002
- 432 views
Matthew Lewis wrote: [snip] > 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 :). [snip] gee, this is pretty interesting and in depth stuff!!! My plan was to cheat a little and write a DLL in standard C which access the C++ objects (like SWIG - but do it manually). ie. convert the OO to a non OO library with a wrapper ... or create a wrapper on a wrapper. Then Euphoria will just call the C routines which will call the C++ routines. It's most likely more work but possibly easier. I actaully started a project to automate most of the C and euphoria code when I did the same thing for Allegro (but never finished it). It couldn't parse header files but I just created data files and it created the C DLL and the Euphoria wrapper. So after all that ... I guess my question should have been how do I create C wrapper for a C++ library?? Thanks, Ray Smith http://rays-web.com