On Oct 18, 2013, at 4:48 AM, Shane Stanley <sstan...@myriad-com.com.au> wrote:
> is there any way to build a call to a C function on the fly? I mean something 
> like pass a string to a method, and have it call the function of that name?


 Short: No. Long: Maybe.

 1) You can put a function in a dynamic library and export it, and load that 
library. If you know its signature, you can then call it.

 2) You can build a look-up table of name -> function pointer mappings inside 
your application, then look up the function pointer by name and call it. You'd 
need to know its signature then, too.

 3) You can build a dynamic library that has this function as its main entry 
point and call that. Essentially a variant of #1. You'll still need to know its 
signature beforehand then

 4) You can use a library like libffi to call a function pointer (using the 
methods in #1 through #3 to get one from a name) even without knowing its 
calling conventions beforehand. As long as you know the signature the moment 
you're calling it and have the proper values, that'll work (this is what you'd 
do if you wanted to make e.g. CoreFoundation APIs accessible to a scripting 
language)

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


_______________________________________________

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

Reply via email to