下面代码调用会bao
const callback = function(value) {
console.log("myMethod called with value:", value);
return value * 2;
};
// 将回调转换为可用的函数指针
const callbackPtr = Module.addFunction(callback, 'ii'); // 'ii' 表示输入和输出都是整数
// 直接将函数指针传递给 C++
const result = Module.ccall(
'callJsMethod',
'number',
['number'], // 函数指针作为整数传递
[callbackPtr]
);
console.log("Result from C++:", result);
错误log:
Error: WXWebAssembly.Module: only support file type .wasm or .wasm.br
at YNe (WAServiceMainContext.js?t=wechat&s=1726909115249&v=3.5.8:1)
at new t (WAServiceMainContext.js?t=wechat&s=1726909115249&v=3.5.8:1)
at convertJsFunctionToWasm (hello.js:2031)
at Object.addFunction (hello.js:2127)
at Oi.heheda (index.js? [sm]:21)
at Object.o.safeCallback (WASubContext.js?t=wechat&s=1726909115249&v=3.5.8:1)
at WASubContext.js?t=wechat&s=1726909115249&v=3.5.8:1
at Fn (WASubContext.js?t=wechat&s=1726909115249&v=3.5.8:1)
at WASubContext.js?t=wechat&s=1726909115249&v=3.5.8:1
at ge (WASubContext.js?t=wechat&s=1726909115249&v=3.5.8:1)(env: macOS,mp,1.06.2407120; lib: 3.5.8)
有解决方案吗。。。