Native Extensions for Parrot: Rather than talk about it at length and not get any code done, I decided, concerning the native extension interface, to just take a simple hello world approach with some outside library.
Qt is a great GUI lib, so I figured what the heck. What resulted was a small API (pxs.h, pxs.c) and 3 ops for loading and calling native methods. I've only tested on Linux, but being an extension API broken platforms wont break the compile, it just means you can't use extensions yet. I wrote the bare minimal glue for Qt in order to do the Hello World. There is no pre-processor, etc. like JNI yet, but it should serve as a good starting point for more discussion and patches. The callnative methods also don't cache subroutine references, although they DO return them in a PMC so you can call them directly again. If you run Linux you might already have Qt installed. Otherwise to play with it you'll have to get it (get the RPM from Redhat) or from www.trolltech.com. I'm not including a lot of info, if you are a hacker grunt you'll figure it out. Here is the sample: # Sample "Hello World" with Qt, via Parrot Native API (PXS) # You'll need to build libPQt.so for this to work, see # pqt.C for more info. # loadlib P0, "libpqt.so" print "Loaded\n" callnative P1, P0, "QApplication_new" restore P2 save "Hello, world!" callnative P1, P0, "QLabel_new" restore P3 #P3 is now a QLabel save 30 save 120 callnative P1, P0, P3, "QLabel_resize" save P3 callnative P1, P0, P2, "QApplication_setMainWidget" callnative P1, P0, P3, "QLabel_show" callnative P1, P0, P2, "QApplication_exec" You can build the shared lib with GCC as follows: perl Configure.pl --ask When asked for LD flags, give it -rdynamic make parrot cd examples/pxs g++ -fPIC -I$QTDIR/include -L$QTDIR -I./include -c PQt.C -lqt gcc -shared -o libPQt.so PQt.o $QTDIR/lib/libqt.so (if you write a plain C extension you don't need g++ or -fPIC) Make sure libPQt.so is then placed somewhere in your LD_LIBRARY_PATH If you do this on windows, change the PASM to libPQt.dll of course. When you run it (requires X on UNIX) you should see _something_ :) And with that, I'll close, rather than explain the ops in detail; I'll wait until people actually care to look at it and ask questions. Have fun! -Melvin