> On Mar 4, 2016, at 4:03 PM, Greg Parker <gpar...@apple.com> wrote: > > >> On Mar 4, 2016, at 2:24 PM, Jonathan Mitchell <li...@mugginsoft.com> wrote: >> >> Hi Alex >> >> Not sure if this will help at all as I am not 100% sure what you are doing. >> In my case, using Mono, I needed to track events being raised in the Mono C >> runtime back into Obj-C space. >> You need some method of defining a call back function in the target C Api - >> without that thinks would look rather bleak. >> >> Basically the C Mono runtime is configured to a call static C function in an >> Obj C .m file in response to a C# managed event firing. >> The static then calls a static method on an Obj-C class. >> This Obj-C static uses collections to track registered events and invokes >> performSelector: on a registered Obj-C target. >> See here: >> https://github.com/ThesaurusSoftware/Dubrovnik/blob/master/Framework/XCode/Representations/DBManagedEvent.m >> >> One of the arguments based in as part of the event callback is a pointer >> that is used as a a key to retrieve the target NSObject. >> This is complicated by the fact that the incoming pointer represents a >> moveable memory location so there is some extra indirection too. >> https://github.com/ThesaurusSoftware/Dubrovnik/blob/master/Framework/XCode/Representations/DBPrimaryInstanceCache.m >> >> This can get a bit complex but its all doable. > > Block objects can help. clang supports block objects in plain C code > (-fblocks, I think).
They're just enabled by default on our platform in all language modes. John. > Your Objective-C code can create a block object that performs the callback > and pass it to the C code to store and call. The block object would capture > the target NSObject so you don't need the dictionary of callback targets. > > > -- > Greg Parker gpar...@apple.com Runtime Wrangler > > > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/rjmccall%40apple.com > > This email sent to rjmcc...@apple.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com