问题遇到的现象和发生背景
想将
https://github.com/qiuxiang/aubiojs
库编译成wasm格式文件,然后在小程序内调用。
在小程序内使用
https://developers.weixin.qq.com/miniprogram/dev/framework/performance/wasm.html
方法来引入使用。
但由于对wasm技术不了解,在用WXWebAssembly.instantiate(path, imports)方法引入时,imports需要传参,如果不传的话就报错,报错内容为:
TypeError: WebAssembly.instantiate(): Import #0 module="a" error: module is not an object or function
把a加进去又有新报错LinkError: WebAssembly.instantiate(): Import #0 module="a" function="a" error: function import requires a callable
就说明有一堆参数要盲猜填写。
然后对比着代码库编译生成的js文件(就是wasm配套的js文件),发现需要入参的参数很多,于是我就无从下手了。
我不清楚这些参数是如何产生的,能否在编译wasm文件时就取消这些入参,假若必传的话我该传啥。
问题相关代码,请勿粘贴截图
WXWebAssembly.instantiate('/utils/aubio.wasm', {
a: {}
}).then(res => {
console.log('WXWebAssembly', res);
const instance = res.instance;
console.log('instance', instance.exports);
instance.exports.then(result => {
console.log('result', result);
})
}).catch(error => {
console.error('error', error);
})
运行结果及报错内容
LinkError: WebAssembly.instantiate(): Import #0 module="a" function="a" error: function import requires a callable
我的解答思路和尝试过的方法
因为不懂wasm编译,所以无从下手。
我想要达到的结果
https://github.com/qiuxiang/aubiojs
编译出的wasm文件能够成功在小程序内使用。