lookupFunction<T extends Function, F extends Function> method

F lookupFunction<T extends Function, F extends Function>(
  1. String symbolName,
  2. {bool isLeaf = false}
)

Looks up a native function and returns it as a Dart function.

T is the C function signature, and F is the Dart function signature.

For example:

int32_t add(int32_t a, int32_t b) {
  return a + b;
}
DynamicLibrary dylib = DynamicLibrary.executable();
final add = dylib.lookupFunction<Int32 Function(Int32, Int32), int Function(int, int)>(
        'add');

isLeaf specifies whether the function is a leaf function. Leaf functions are small, short-running, non-blocking functions which are not allowed to call back into Dart or use any Dart VM APIs. Leaf functions are invoked bypassing some of the heavier parts of the standard Dart-to-Native calling sequence which reduces the invocation overhead, making leaf calls faster than non-leaf calls. However, this implies that a thread executing a leaf function can't cooperate with the Dart runtime. A long running or blocking leaf function will delay any operation which requires synchronization between all threads associated with an isolate group until after the leaf function returns. For example, if one isolate in a group is trying to perform a GC and a second isolate is blocked in a leaf call, then the first isolate will have to pause and wait until this leaf call returns.

Implementation

external F lookupFunction<T extends Function, F extends Function>(
    String symbolName,
    {bool isLeaf = false});