Re: Eval() ?
Re: Eval() ?
- Subject: Re: Eval() ?
- From: Brett Powley <email@hidden>
- Date: Fri, 3 Mar 2006 14:57:50 +1100
On 03/03/2006, at 1:00 PM, Andrew Farmer wrote:
On 02 Mar 06, at 11:28, Thierry Passeron wrote:
Hello there,
Is there an Eval() like function in cocoa that would eval a string
and execute it as if it was a code.
like:
id object=NSEval(@"[SomeClass
method1:aparameter :anOtherparameter]" );
would be the same as:
id object=[SomeClass method1:aparameter :anOtherparameter];
Is it possible in Objective-C's Cocoa API ?
Not directly.
Cocoa is a superset of C, which is a compiled language; as such
there's no direct way to compile and run code at runtime. However,
there are ways to construct method calls, so long as that's all
you're doing. It's difficult, however; you may want to try
explaining what you're after to see if there's some more
straightforward way of doing what you're looking for.
This isn't really correct.
Objective-C is a superset of C with a dynamic object model, so that
you *can* determine properties about an object at run-time and invoke
methods on it. Cocoa is a library/framework written in Objective-C.
What you need to look at is the performSelector: methods of NSObject.
For example, you could do:
id object = [someObject performSelector:sel_getUid("method1")
withObject:aparameter withObject:antOtherparameter];
For method calls that you can't do using performSelector (i.e. those
with arguments or return values that aren't NSObjects), you can use
NSInvocation.
Cheers,
Brett
--------------------------------------------------------------
Brett Powley -- PhD Candidate
Centre for Language Technology, Macquarie University, Australia
p: +61-402-013050 f: +61-2-90120813 e: email@hidden
faciendi plures libros nullus est finis
frequensque meditatio carnis adflictio est
--------------------------------------------------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Eval() ? (From: Thierry Passeron <email@hidden>) |
| >Re: Eval() ? (From: Andrew Farmer <email@hidden>) |