• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Calling an object from a C function
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling an object from a C function


  • Subject: Re: Calling an object from a C function
  • From: Ken Thomases <email@hidden>
  • Date: Wed, 20 Aug 2008 05:16:46 -0500

On Aug 20, 2008, at 4:21 AM, Antonio Nunes wrote:

I don't know how this would scale to 'super'. I don't think you can pass in a pointer to super, as that is not how the mechanism works. While "self" is a variable name "super" is a flag to the compiler telling it where to begin searching for the method to perform. That wouldn't work outside of the object's context like in a C function. You would have to find a way access the superclass's methods within the callback function. I suppose it would involve calling objc_msgSendSuper or objc_msgSendSuper_stret directly, but that is unknown territory to me. I'd be interested myself in how that is done if anyone is willing to supply the answer.

Well, you can try to achieve this result with the Objective-C runtime. The better approach would be to have the C function be a very simple wrapper around an Objective-C method (as you illustrated) and then have that method invoke 'super' if necessary.


If you really wanted to do it directly, you could grab the implementation for the method, a function pointer, and call through that:

	Class theSuperClass = [anObject superclass];
	SEL theSelector = @selector(someMethod);
	if ([theSuperClass instancesRespondToSelector:theSelector])
	{
		IMP f = [theSuperClass instanceMethodForSelector:theSelector];
		f(anObject, theSelector);
	}

Cheers,
Ken
_______________________________________________

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


  • Follow-Ups:
    • Re: Calling an object from a C function
      • From: Antonio Nunes <email@hidden>
References: 
 >Calling an object from a C function (From: Gilbert Mackall <email@hidden>)
 >Re: Calling an object from a C function (From: David Duncan <email@hidden>)
 >Re: Calling an object from a C function (From: Charlie Dickman <email@hidden>)
 >Re: Calling an object from a C function (From: David Duncan <email@hidden>)
 >Re: Calling an object from a C function (From: Charlie Dickman <email@hidden>)
 >Re: Calling an object from a C function (From: Antonio Nunes <email@hidden>)

  • Prev by Date: Re: This document's file has been changed by another application?
  • Next by Date: Re: Best Way to Handle Properties?
  • Previous by thread: Re: Calling an object from a C function
  • Next by thread: Re: Calling an object from a C function
  • Index(es):
    • Date
    • Thread