I dug a bit into the basics of a new Xojo Framework-compatible MacOS X library and got stuck on the Objective C Runtime. Many things are really blazing fast there, and as I never really got accustomed to the Introspection class I set one up using ObjC features. This works nicely so far, but: Could somebody explain me how to read the structure of a objc_method_description? Is that two pointers to CStrings or what?
(If you are interested, tell me and Ill upload the project.)
a selector is not a normal pointer there. Use sel_getName function to query it’s text.
by the way, directly reading in some data structures may give trouble in future.
Structure objc_method_description
name As Ptr // opaque SEL type, use sel_getName to get it as a CString
type As CString
End Structure
You would then call method_getDescription like this:
Declare Function method_getDescription Lib "/usr/lib/libobjc.dylib" (m As Ptr) As Ptr
Dim descriptionPtr As Ptr = method_getDescription(myMethodPtr)
If descriptionPtr <> Nil Then
Dim description As objc_method_description = descriptionPtr.objc_method_description
// do stuff
End If
selectors are not simply string pointers. You pass them like pointers and sel_getName function gives a CString for them.
It’s not deprecated, but for 64bit part of the objc-runtime requires to use accessor functions instead of looking in structures.
Thanks again, Christian!
Somehow this one part doesn’t want to work. Still looks like an encoding error.
But while the rest is doing nicely and I am amazed how fast although I convert a lot between the data types : thanks for the warning again. I check Apple’s docs on each implementation step to see if some deprecation or advice is given and don’t implement those that Apple suggests better not to use.
Thanks a lot, Eli!
I finally got the description working too. I understood the docs as if the method would deliver a structure like many AppKit methods do. But it’s more or less the ptr to a struct. Phew!
And having built the method, I found it delivers the same values I already got in form of two independent properties
Oh! Is there a difference in how Core.Memoryblocks are handled compared to the old ones? When I try to call the method like you described on a xojo.core.MB, the compiler tells me it expected a ptr, not a MB.
Will this work on an immutable MB anyway?
Oh thanks again! I overread that part of the docs
but freeing doesn’t work for MBs as well as MMBs. Okay, guess I’ll have to live with a little leak probably for the next time.