* Invokes the native function with a native string return value.
* Returns a {@link RubyString} to ruby.
*/
private static final class StringInvoker implements FunctionInvoker {
public final IRubyObject invoke(Ruby runtime, Function function, Object[] args) {
Pointer address = function.invokePointer(args);
if (address == null) {
return runtime.getNil();
}
int len = (int) address.indexOf(0, (byte) 0);
if (len == 0) {
return RubyString.newEmptyString(runtime);
}
ByteList bl = new ByteList(len);
bl.length(len);
address.read(0, bl.unsafeBytes(), bl.begin(), len);
return RubyString.newString(runtime, bl);
}