On 11/14/07, Duncan McGregor <dun...@oneeyedmen.com> wrote:
Thank you Timothy, Greg and Mike.
I had found the C interface to Objective-C (There's a tentative
wrapper at the end of this mail).
My problem was that in order to call Objective-C methods I need to
call NSSelectorFromString (a C function). This takes an NSString. In
order to get an NSString from a char* (and hence easy JNA
marshalling) I wanted to call the static method
NSString::stringWithUTF8String:(const char *), the problem being that
in order to call this static method I needed a selector, which meant
calling NSSelectorFromString, which needs an NSString... So I was
kind of hoping there was some short-cut to calling a static method,
maybe in the way that you can call C++ functions from C if you can
predict the name mangling.
Our real Cocoa hackers pointed out that CFString is compatible with
NSString and can be built with the plain C function
CFStringCreateWithCString, breaking the cycle and letting me get
selectors for other purposes.
Note you have to CFRelease the string created from CFStringCreateXxxx.
Consider dropping down to the objc runtime API for this type of stuff.
SEL selector = sel_getUid("someMessage:a:b:c")
..of course then look at probing class and method information directly
using the objc runtime API which will yield you SEL as well.
You could also have the JNI code have vars defined for the selectors
it will need to do its bridging work without the need to look them up
(@selector(blah)).
It is non-trivial (to some extent) to deal with the rules of when to
use the various objc_msgSend varients.
-Shawn