Open burhon97 opened 1 year ago
I'm trying to read file main.wasm with WebAssembly.instantiate() and get function add() . But got this error:
main.wasm
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); }
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?
react-native-webassembly
I'm trying to read file
main.wasm
with WebAssembly.instantiate() and get function add() . But got this error:File
main.wasm
build with go:Go code:
Build wasm file and linking custom assets to iOS and Android project:
Code of js in React-Native:
Versions