I’ve started working on a secret MacOSX project. I decided to use Apple’s Cocoa framework, so that means I have to use Objective-C. The backend I’m basing my project on is in C++ and uses the libsigc++ callback library as an important component of its interface with the frontend. So how do you setup ObjC methods to be called back?
Use my glue header. It will create glue functions at compile time for calling objc_msgSend() with the appropriate arguments.
SignalActivated.connect (sigc::bind(sigc::ptr_fun(objcsigcglue<bool>), self, @selector(CatchSignal:)));
This will call [self CatchSignal:boolValue]. Pretty neat, right? For the majority of callbacks that don’t accept arguments, a mere function pointer cast is needed:
BoringSignal.connect (sigc::bind(sigc::ptr_fun((msgFtn)objc_msgSend), self, @selector(boringSignalCatch:)));
Update: I fixed objcsigcglue.h to work with references that are passed to the callback. It should be much more flexible with other types I haven’t anticipated too.