[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Function as an argument
From: |
Marcus G. Daniels |
Subject: |
Re: Function as an argument |
Date: |
04 Apr 2000 14:44:50 -0700 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "AO" == Akiko Ogawa <- RS/GIS lab <address@hidden>> writes:
AO> 1) In my example,
AO> assuming that -scientificTest: takes one arguments and
AO> -conventionalTest: takes two arguments (though here it doesn't),
AO> is there any nice way for the -goThroughtEggWith:InObj function to
AO> detect how many arguments a passed function takes so that it can
AO> switch between [obj perform: sel with: egg] and [obj perform: sel
AO> with: egg with: somethingElse] in itself?
Well, you could look at the method name and count the ":" characters,
and do a `switch' on that number.
Another idea is to use the FArguments/FCall interface so that the
information is all packaged together. (See below.)
AO> 2) Can a selecter be a function that returns a value, as in
AO> M(getSomething), where, -(int) getSomething?
Strictly speaking, no. It has to be a an `id'-like thing (typically
a 32 bit value). `int' will work most places.
#import <simtools.h> // initSwarm
#import <defobj/Create.h> // CreateDrop
@interface Target: CreateDrop
@end
@implementation Target
- (void)message: (double)arg1 arg2: (int)arg2 arg3: (const char *)arg3
{
printf ("arg1: %f arg2: %d arg3: `%s'\n", arg1, arg2, arg3);
}
@end
int
main (int argc, const char **argv)
{
initSwarmBatch (argc, argv);
{
id obj = [Target create: globalZone];
SEL sel = M(message:arg2:arg3:);
id <FArguments> fa = [FArguments createBegin: globalZone];
[fa setSelector: sel];
[fa addDouble: 2.0];
[fa addInt: 3];
[fa addString: "Hello World"];
fa = [fa createEnd];
{
id <FCall> fc =
[FCall create: globalZone target: obj selector: sel arguments: fa];
[fc performCall];
}
}
return 0;
}
/*
Local Variables:
compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc -DAPPNAME=fcall
-o fcall -Wall -Werror -g -Wno-import -I$SWARMHOME/include/swarm
-L$SWARMHOME/lib/swarm fcall.m -lswarm -lobjc"
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.