return runtime.newFloat(buffer.getFloat(index));
case DOUBLE:
return runtime.newFloat(buffer.getDouble(index));
case POINTER:
return new Pointer(runtime, NativeMemoryIO.wrap(runtime, buffer.getAddress(index)));
case STRING:
return getStringParameter(runtime, buffer, index);
case BOOL:
return runtime.newBoolean(buffer.getByte(index) != 0);
default:
throw runtime.newTypeError("invalid callback parameter type " + type);
}
} else if (type instanceof CallbackInfo) {
final CallbackInfo cbInfo = (CallbackInfo) type;
final long address = buffer.getAddress(index);
return address != 0
? new Function(runtime, cbInfo.getMetaClass(),
new CodeMemoryIO(runtime, address),
cbInfo.getReturnType(), cbInfo.getParameterTypes(),
cbInfo.isStdcall() ? CallingConvention.STDCALL : CallingConvention.DEFAULT, runtime.getNil())
: runtime.getNil();
} else if (type instanceof StructByValue) {
StructByValue sbv = (StructByValue) type;
final long address = buffer.getStruct(index);
DirectMemoryIO memory = address != 0
? new BoundedNativeMemoryIO(runtime, address, type.getNativeSize())
: new NullMemoryIO(runtime);
return sbv.getStructClass().newInstance(runtime.getCurrentContext(),
new IRubyObject[] { new Pointer(runtime, memory) },
Block.NULL_BLOCK);
} else if (type instanceof MappedType) {
MappedType mappedType = (MappedType) type;
return mappedType.fromNative(runtime.getCurrentContext(), fromNative(runtime, mappedType.getRealType(), buffer, index));