lookup<T extends NativeType> method

Pointer<T> lookup<T extends NativeType>(
  1. String name
)

Looks up a symbol in the DynamicLibrary and returns its address in memory.

Throws an ArgumentError if it fails to lookup the symbol.

While this method checks if the underyling wasm symbol is a actually a function when you lookup a NativeFunction<T>, it does not check if the return type and parameters of T match the wasm function.

Implementation

Pointer<T> lookup<T extends NativeType>(String name) {
  WasmSymbol symbol = symbolByName(boundMemory, name);
  if (isNativeFunctionType<T>()) {
    if (symbol is FunctionDescription) {
      return new Pointer<T>.fromAddress(symbol.tableIndex, boundMemory);
    } else {
      throw new ArgumentError(
          'Tried to look up $name as a function, but it seems it is NOT a function!');
    }
  } else {
    return new Pointer<T>.fromAddress(symbol.address, boundMemory);
  }
}