On Dec 1, 2008, at 8:52 PM, Luke the Hiesterman wrote:
parse string into commandString and argumentString then do:

SEL command = NSSelectorFromString(commandString);
[anObject performSelector:command withObject:argumentString];

If you're trying to execute a C function, then you could create class methods to wrap them.

Except, of course, that the above won't work if the functionality that John wants to access is not accessible as a method taking a single NSObject type (or subclass) argument on anObject.

Accessing straight C based API dynamically (like NSLog() -- as in the OP's example code) -- from an interpreted environment -- is, quite frankly, a pain in the butt. At the least, you need to look up the symbol. More complex, if the function requires arguments, you need to determine their types and how to encode them appropriately to create a call to said function.

Mac OS X offers two facilities to assist in this; libffi and BridgeSupport.

Libffi is an open source bit of code that allows one to create something akin to a C function call site on the fly.

BridgeSupport offers a bunch of metadata as to the arguments and return types for most of the APIs on the system and is specifically targeted to providing metadata for API that is not fully described by the metadata found within the ObjC runtime.

The two are most oft used to providing bridging technologies like MacRuby, PyObjC, RubyCocoa, and Scripting Bridge.

But they aren't terribly easy to use. Unless the goal is an open ended interface, one is generally better off providing a hardwired interface to a given API.

b.bum
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to