summaryrefslogtreecommitdiff
path: root/MLKRoot.m
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-07-29 16:35:29 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-07-29 16:35:29 +0200
commit04fd4986f83c8bf623578511e075376c671c3555 (patch)
tree4e55393310f3b97333c1bfda3b9161448b7570b1 /MLKRoot.m
parentc51d47e817c4a5c6a9b5a901d1825370a6552398 (diff)
Add SEND-BY-NAME.
Diffstat (limited to 'MLKRoot.m')
-rw-r--r--MLKRoot.m54
1 files changed, 54 insertions, 0 deletions
diff --git a/MLKRoot.m b/MLKRoot.m
index 3ad0f01..b133265 100644
--- a/MLKRoot.m
+++ b/MLKRoot.m
@@ -491,4 +491,58 @@ static id truify (BOOL value)
else
{ RETURN_VALUE ([cl intern:@"T"]); }
}
+
++(NSArray *) send_by_name:(NSArray *)args
+{
+ NSString *methodName = denullify ([args objectAtIndex:1]);
+ id object = denullify ([args objectAtIndex:0]);
+ NSInvocation *invocation;
+ SEL selector;
+ NSMethodSignature *signature;
+ int i;
+
+ selector = NSSelectorFromString (methodName);
+ if (!selector)
+ {
+ [NSException raise:@"MLKNoSuchSelectorError"
+ format:@"Could not find a selector named %@", methodName];
+ }
+
+ signature = [object methodSignatureForSelector:selector];
+ if (!signature)
+ {
+ [NSException raise:@"MLKDoesNotUnderstandError"
+ format:@"%@ does not respond to selector %@", object, methodName];
+ }
+
+ invocation = [NSInvocation invocationWithMethodSignature:signature];
+
+ [invocation setSelector:selector];
+ [invocation setTarget:object];
+
+ for (i = 2; i < [args count]; i++)
+ {
+ id argument = denullify ([args objectAtIndex:i]);
+ [invocation setArgument:&argument atIndex:i];
+ }
+
+ [invocation invoke];
+
+ if (strcmp ([signature methodReturnType], @encode(void)) == 0)
+ {
+ return [NSArray array];
+ }
+ else if (strcmp ([signature methodReturnType], @encode(BOOL)) == 0)
+ {
+ BOOL returnValue;
+ [invocation getReturnValue:&returnValue];
+ RETURN_VALUE (truify (returnValue));
+ }
+ else
+ {
+ id returnValue;
+ [invocation getReturnValue:&returnValue];
+ RETURN_VALUE (returnValue);
+ }
+}
@end