Re: cross platform GUI suggestions for Euphoria
- Posted by David Cuny <dcuny at LANSET.COM> Oct 02, 2000
- 399 views
mic wrote: >> I know about the C++ Object Oriented part being >> hard to wrap up properly. > > I wouldn't say it's hard, I'd say it's freaking impossible > (just about). When you write a wrapper, you need to use a C++ compiler. You define the interface something like this: extern "C" __declspec(dllexport) blah_do_something( blah self ) { self->do_something() } Here's the rundown: [ extern "C" ] This prevents that C++ compiler from mangling the routine name, so it's visible in the DLL. Otherwise, you have no guarantee what the routine name will look like once the C++ compiler gets done with it. [ __declspec(dllexport) ] Only needed on the Windows platform. This tells the compiler and linker that this routine is going to be exported (visible) in the DLL. [ blah_do_something ] The class name is prefixed to the function, to make it unique from all those other 'do_something' routines in the other classes. Actually, you probably want to name it something like 'wrap_blah_do_something' out of sheer paranoia. [ (blah this) ] In C++, you can just call the routine like this: someBlah.my_routine() and the object is implicitly passed. We have to make this explicit in our interface. [ self->do_something() ] This is the actual call. We take the object that we passed, and call the routine. It's actually a pretty mechanical process, once you've done it a couple of times. There's actually a program called SWIG that is designed to process C/C++ libraries, and generate this sort of wrapper automatically. I've written a fairly simple module to SWIG that will generate the source code for DLLs as well as the Euphoria code to link to the compiled DLL. Unfortunately, I can no longer get my code to work properly - calls to stdio cause the program to choke. I blame the Borland compiler, and after struggling with it for a while, gave up and have rewritten the SWIG code in Euphoria. It doesn't handle as large a class of C/C++ code, but it's decent. It was going well, but I got sidetracked into writing a yacc-like front end to a LL1 grammar parser... I hope this clarifies things. -- David Cuny