Re: Sending messages without knowing number of args and types at compile time
Re: Sending messages without knowing number of args and types at compile time
- Subject: Re: Sending messages without knowing number of args and types at compile time
- From: Greg Parker <email@hidden>
- Date: Mon, 1 Feb 2010 11:25:49 -0800
On Feb 1, 2010, at 3:30 AM, Per Bull Holmen wrote:
> I've been playing around with the idea of making a simple bridge between Objective-C (running under Cocoa) and a script language. Not for the API, that is, but for user defined classes and methods. For this reason, I'd like to know whether there are any other ways than NSInvocation to send a message without knowing arg types and numbers at compile time. Non-hackish ways, that is. I see that people used objc_msgSendv earlier, but it is no longer available in Objective-C 2.0. Also, using objc_msgSend doesn't seem to be platform independent (PPC/Intel). So, does this mean that NSInvocation is the only civilised way to go? NSInvocation is great, it's just that there's a lot of overhead, so I assume this is because it has functionality I might not need?
NSInvocation is the most architecture-neutral way to go.
The best option outside NSInvocation is to use libffi to build calls to objc_msgSend. libffi-based code is architecture-neutral for simple examples, but falls into architecture-specific holes in more complicated examples. One place where it is architecture-specific is methods that return C structs: they may use objc_msgSend or objc_msgSend_stret depending on the struct's layout, and different architectures have different rules.
Using objc_msgSend and especially objc_msgSendv directly is almost always architecture-specific.
--
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