Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Exception in HostFunction: function lookup failed #16

Open
burhon97 opened this issue Jul 26, 2023 · 1 comment
Open

Error: Exception in HostFunction: function lookup failed #16

burhon97 opened this issue Jul 26, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@burhon97
Copy link

burhon97 commented Jul 26, 2023

I'm trying to read file main.wasm with WebAssembly.instantiate() and get function add() . But got this error:

Error: Exception in HostFunction: function lookup failed

File main.wasm build with go:

Go code:

package main

import (
	"fmt"
	"syscall/js"
)

func add(this js.Value, inputs []js.Value) interface{} {
	a := inputs[0].Float()
	b := inputs[1].Float()
	return a + b
}

func main() {
	fmt.Println("Hello world!")
	ch := make(chan struct{}, 0)
	js.Global().Set("add", js.FuncOf(add))
	<-ch
}

Build wasm file and linking custom assets to iOS and Android project:

GOOS=js GOARCH=wasm go build -o main.wasm
cd ../
react-native-asset

Code of js in React-Native:

import * as WebAssembly from 'react-native-webassembly';
import {Dirs, FileSystem} from 'react-native-file-access';
import {Base64Url} from './src/base64url';

async function wasmTest() {
      const src = `${Dirs.MainBundleDir}`;
      const result =  await FileSystem.readFile(`${src}/main.wasm`, "base64")
      // console.log('result', result);
      const buffer = Base64Url.toBuffer(result);
      console.log('buffer', buffer.length);

      const module = await WebAssembly.instantiate<{
        add: (a: number, b: number) => number;
      }>(new Uint8Array(buffer));
      
      const secondResult = module.instance.exports.add(300, 200);
      console.log('second result = ', secondResult);
}

Versions

  • Go version: 1.20.6 darwin/arm64
  • Node.js version: 18.15.0
  • React-Native version: 0.72.3
@cawfree
Copy link
Owner

cawfree commented Nov 3, 2023

Sounds like it was unable to find the functions we expect the Wasm to.

I'm unfamiliar with the formatting of this file - can you confirm that it works within a different runtime than react-native-webassembly?

@cawfree cawfree added the bug Something isn't working label Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants