Re: Returning a string value from a c function to a Objective-C class method. Is there an approved approach?
Re: Returning a string value from a c function to a Objective-C class method. Is there an approved approach?
- Subject: Re: Returning a string value from a c function to a Objective-C class method. Is there an approved approach?
- From: Greg Parker <email@hidden>
- Date: Fri, 04 Mar 2016 16:03:21 -0800
> On Mar 4, 2016, at 2:24 PM, Jonathan Mitchell <email@hidden> 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). 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 email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden