Building NSInvocation instances is even easier than doing everything by
hand -- for example the parsing of ObjC parameter type encoding strings
is much less work, because the NSMethodSignature objects at least split
them
correctly for you. You just have to create the object, set the
parameters,
execute the call and retrieve the return value -- like in this
pseudocode
snippet:
SEL sel = sel_registerName("someSelector");
NSMethodSignature *sig = [someObject methodSignatureForSelector:sel];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
[inv setTarget:someObject];
[inv setSelector:sel];
for (int i = 2; i < [sig numberOfArguments]; i++)
[inv setArgument:convertArgumentFromScheme(i-2, [sig
getArgumentTypeAtIndex:i])
atIndex:i];
[inv invoke];
void *rbuf = alloca([sig methodReturnLength]);
[inv getReturnValue:rbuf];
convertReturnValueToScheme([sig methodReturnType], rbuf);
[inv release];
[sig release];