fromFunction<T extends Function> method
- @DartRepresentationOf("T") Function f,
- [Object? exceptionalReturn]
Convert Dart function to a C function pointer, automatically marshalling the arguments and return value
If an exception is thrown while calling f()
, the native function will return exceptionalReturn
, which must be assignable to return type of f
.
The returned function address can only be invoked on the mutator (main) thread of the current isolate. It will abort the process if invoked on any other thread.
The pointer returned will remain alive for the duration of the current isolate's lifetime. After the isolate it was created in is terminated, invoking it from native code will cause undefined behavior.
Does not accept dynamic invocations -- where the type of the receiver is dynamic
.
Implementation
external static Pointer<NativeFunction<T>> fromFunction<T extends Function>( @DartRepresentationOf("T") Function f, [Object? exceptionalReturn]);
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-ffi/Pointer/fromFunction.html