• 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: Create command from string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Create command from string


  • Subject: Re: Create command from string
  • From: Bill Bumgarner <email@hidden>
  • Date: Mon, 01 Dec 2008 23:29:38 -0800

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 (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


References: 
 >Create command from string (From: John Murphy <email@hidden>)
 >Re: Create command from string (From: Luke the Hiesterman <email@hidden>)

  • Prev by Date: Xcode messes up my Log Files
  • Next by Date: Re: best way to add transitions
  • Previous by thread: Re: Create command from string
  • Next by thread: Re: Create command from string
  • Index(es):
    • Date
    • Thread