[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using selectors
From: |
Marcus G. Daniels |
Subject: |
Re: using selectors |
Date: |
20 Jul 1998 11:56:35 -0700 |
>>>>> "JM" == James Marshall <address@hidden> writes:
JM> Maybe I should be trying to use the perform method with a selector
JM> and argument instead, but I'm not sure how I'd do that in this
JM> case? Someone please give me the correct syntax!
It isn't a question of syntax. EZGraph just isn't set up to pass arguments
to it's selector.
If you use ActiveGraph directly, and call setArg:ToString: with
stringified versions of the integers arguments you wanted, then you
could sort of do it. (ugh, gross!)
And if you are really in a wicked mood, you could encapsulate the index in
a closure, along these lines...
#include <objc/objc-api.h>
#include <objc/Object.h>
void
replace_imp (Class class, SEL sel, IMP imp)
{
Method_t method = class_get_instance_method (class, sel);
method->method_imp = (IMP)imp;
#if 0
__objc_install_premature_dtable (class); /* GCC < 2.8 */
#else
class->dtable = objc_get_uninstalled_dtable (); /* GCC >= 2.8 */
#endif
}
@interface Test: Object
- run;
@end
@implementation Test
- run
{
printf ("Default Behavior\n");
return self;
}
- runValue: (int)i
{
static updatedFlag = NO;
id func (id self, SEL aSel)
{
printf ("Behavior#: %d\n", i);
return self;
}
if (!updatedFlag)
{
replace_imp ([self class], @selector (run), (IMP)func);
updatedFlag = YES;
}
[self run];
}
@end
main ()
{
id obj = [[Test alloc] init];
int i;
for (i = 0; i < 5; i++)
[obj runValue: i];
}
/*
Local Variables:
compile-command: "gcc -g closure.m -lobjc -o closure"
End:
*/
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
==================================
- using selectors, James Marshall, 1998/07/17
- Re: using selectors, Marcus G. Daniels, 1998/07/17
- Re: using selectors, James Marshall, 1998/07/20
- Re: using selectors, Marcus G. Daniels, 1998/07/20
- Re: using selectors, James Marshall, 1998/07/21
- Re: using selectors, Marcus G. Daniels, 1998/07/21