void addFunction()

in wasm/lib/src/module.dart [168:189]


  void addFunction(String moduleName, String name, Function fn) {
    final index = _getIndex(moduleName, name);
    final imp = _importDescs[index];

    if (imp.kind != wasmerExternKindFunction) {
      throw WasmError('Import is not a function: $imp');
    }

    final funcType = imp.type as Pointer<WasmerFunctype>;
    final returnType = runtime.getReturnType(funcType);
    final wasmFnImport = calloc<_WasmFnImport>();
    wasmFnImport.ref.returnType = returnType;
    _wasmFnImportToFn[wasmFnImport.address] = fn;
    final fnImp = runtime.newFunc(
      _importOwner,
      funcType,
      _wasmFnImportTrampolineNative,
      wasmFnImport,
      nullptr, // TODO(#47): Re-enable _wasmFnImportFinalizerNative.
    );
    _imports.ref.data[index] = runtime.functionToExtern(fnImp);
  }