From: Arno P. <ar...@pu...> - 2011-05-20 06:57:06
|
On 5/19/11 11:47 PM, Panayotis Katsaloulis wrote: >>> 1) what is the reason of this variable >>> >>> static NSObject* dispatchObject = nil; >>> >>> in the NSObject class of the C backend? >> >> The C wrapper use this object to call the performSelectorOnMainThread: >> method on a real Objective-C object. > > The reason I ask is because I can not find it anywhere in the code, and probably it is a leftover. ah, ok, you are right. It is indeed a left-over. The dispatcher object is created in performSelectorOnMainThread. >>> 2) I have a JAVA_OBJECT , say "o1" >>> This object, (in java) it has a specific method, let's say >>> public void myMethod(Object val) {..} >>> >>> How do I call this method from inside C, given I have the pointer o1 of this object? >> >> It depends if the call is made through an interface type or class type. >> I suggest that you write a mini-Java program that does this call (in >> Java) and then cross-compile it with --target=posix. Then you can look >> at the generated code. > > I want to do this in the compatibility library for arbitrary objects, in order to implement a method of an interface, so I don't know in advance what this would be. > Do you believe I should use reflection then? hmm. Do you want to be able to call arbitrary *methods* or a certain method on arbitrary *objects*? For the former you need reflected, for the latter not. Actually, take a look at [DispatcherObject run] (in NSObject.m) to get an idea how you can invoke a Java method from C code. > And a last probably silly question: > How do I convert an ObjC String to java_lang_String ? > (and for completeness and back?) NSString* toNSString(JAVA_OBJECT o) JAVA_OBJECT toJavaString(NSString* str) both defined in NSString.m Arno |