withCharPtrCallback function

Future<String> withCharPtrCallback(
  1. dynamic func(
    1. Pointer<NativeFunction<Void Function(Pointer<Char>)>>
    )
)

Implementation

Future<String> withCharPtrCallback(
    Function(Pointer<NativeFunction<Void Function(Pointer<Char>)>>)
        func) async {
  JSArray retVal = createVoidPointerCallback();
  var promise = retVal.toDart[0] as JSPromise<JSNumber>;

  var fnPtrAddress = retVal.toDart[1] as JSNumber;
  var fnPtr = Pointer<NativeFunction<Void Function(Pointer<Char>)>>.fromAddress(
      fnPtrAddress.toDartInt);
  func(fnPtr);
  final addr = await promise.toDart;
  return Pointer<Utf8>.fromAddress(addr.toDartInt).toDartString();
}