Re: Eval() ?
Re: Eval() ?
- Subject: Re: Eval() ?
- From: Andrew Farmer <email@hidden>
- Date: Thu, 2 Mar 2006 20:02:23 -0800
On 02 Mar 06, at 19:57, Brett Powley wrote:
On 03/03/2006, at 1:00 PM, Andrew Farmer wrote:
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.
Point is, there's no way you can expect to run something like
char *eval_str = "[Object doSomething:someFunctionCall(etc etc)]";
eval(eval_str);
and expect it to work. Reflection is a powerful technique, but it
only goes so far.
My point stands that it'd probably help - a LOT - to know what the OP
is really trying to do, and it might make sense to look for an
alternate way of going about it.
Attachment:
PGP.sig
Description: This is a digitally signed message part
_______________________________________________
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>) |
| >Re: Eval() ? (From: Brett Powley <email@hidden>) |