Easy Perl callbacks for SWIG
The people who maintain SWIG like to do this with something they call a "director", which is basically a way to let you override virtual functions from the scripting language. I see two problems with that:
1 - There's no Perl support for it yet, and there doesn't seem to be any coming
2 - Doing callbacks by overriding classes is a pain in the butt. If I want (e.g.) a button press to be labeled "quit" and to quit the program when pressed, I should be able to pass in: sub{ exit(0); } to the button, not override a silly buttonListener class.
Anyway, stealing liberally from code I've found on the net, I managed to put together something very easy and usable. It also makes use of the excellent boost::function and boost::bind wrappers, but allows you to pass a perl anonymous subroutine or subroutine refrence as if it were either a void(void) C function, or a boost::function
Without further ado, here's a header to be swigged and included before any callback is defined, that should make using Perl subs as C++ callbacks completely transparent:
PerlFunction.h