long numArgs = (Long)pSig.send("numberOfArguments");
long respondsToSelector = msg(parent, "respondsToSelector:", selector );
if ( respondsToSelector > 0 ){
long impl = msg(parent, "methodForSelector:", selector);
Pointer pImpl = new Pointer(impl);
Function func = Function.getFunction(pImpl);
long returnType = (Long)pSig.send("methodReturnType");
String strReturnType = new Pointer(returnType).getString(0);
String prefixes = "rnNoORV";
int offset = 0;
while ( prefixes.indexOf(strReturnType.charAt(offset)) != -1 ){
offset++;
if ( offset > strReturnType.length()-1 ){
break;
}
}
if ( offset > 0 ){
strReturnType = strReturnType.substring(offset);
}
Object[] args = new Object[new Long(numArgs).intValue()];
args[0] = peer;
args[1] = parent;
for ( int i=2; i<numArgs; i++){
long argumentSigAddr = (Long)pSig.send("getArgumentTypeAtIndex:", i);
String argumentSignature = new Pointer(argumentSigAddr).getString(0);
LongByReference ptrRef = new LongByReference();
msg(invocation, "getArgument:atIndex:", ptrRef.getPointer(), i);
args[i] = ptrRef.getValue();
}
char retTypeChar = strReturnType.charAt(0);
Class retType = null;
switch ( retTypeChar){
case 'v':
retType = void.class; break;
case 'f':
retType = float.class; break;
case 'd':
retType = double.class; break;
case '*':
retType = String.class; break;
case 'i':
case 'I':
case 's':
case 'S':
case 'c':
case 'C':
case 'B':
retType = int.class;break;
case 'l':
case 'L':
case 'q':
case 'Q':
retType = long.class;break;
case '@':
case '#':
case ':':
case '^':
case '?':
retType = Pointer.class; break;
default:
// If we don't know how to handle the return type properly,
// then let's just give up and pass it to the parent object
// the normal way
//System.out.println("We give up... passing "+sel(selector)+" to parent");
msg(invocation, "invokeWithTarget:", parent);
return;
}
Object retVal = func.invoke(retType, args);
if ( !void.class.equals(retType)){
// We need to set the return value.
if ( retVal == null ){