Webassembly from Javascript
Webassembly from Javascript
我有一个C++程序,有1000多行(使用vector和stdlib.h(。该程序由一个函数组成,该函数以5个无符号int(或1个无符号char和4个无符号整数(为输入,返回一个字符串或4个无签名int(我不知道如何返回数字数组,所以我使用字符串(。我使用WasmExplorer将该程序编译为.wasm文件。
如何从javascript中调用.wasm文件中的函数,得到结果?我试过:
let squarer;
function loadWebAssembly (fileName) {
return fetch (fileName)
.then (response => response.arrayBuffer ())
.then (bits => WebAssembly.compile (bits))
.then (module => {return new WebAssembly.Instance (module)});
};
loadWebAssembly ('http://test.ru/squarer.wasm')
.then (instance => {
squarer = instance.exports._Z7squareri;
console.log ('Finished compiling! Ready when you are ...');
});
Chrome中的错误(我有29Kb.wasm文件(
Uncaught (in promise) RangeError: WebAssembly.Instance is disallowed on the main thread, if the buffer size is larger than 4KB. Use WebAssembly.instantiate.
如何从JS中调用函数(附示例(?
铬中wasm/wasm-000197c6/wasm-000197c6-22的特定功能
错误消息中明确说明了问题和解决方案:应该使用WebAssembly.instantiate()
函数而不是WebAssembly.Instance()
构造函数。
相关文章:
- 如何解决"invalid conversion from 'char' to 'const char*'"
- 如何在本地机器上运行c++和javascript客户端代码(hackerbank风格)
- 如何将C++闭包与变量参数同时重用——类似于JavaScript
- 嘿,我正在尝试将此c ++转换为javascript,但有些东西不起作用
- C++中的 JavaScript 样式闭包
- std::async from std::async in windows xp
- OpenCV(C++)处理来自JavaScript / Web Assembly的图像数据
- 在C++中嵌入 Mozilla 的 JavaScript 引擎
- Javascript 找不到使用 emscripten 编译的导出 WASM 函数
- std::is_reference from std::any
- 在Javascript和C++中计算MD5哈希的不同结果
- 将Wiimote MAC地址转换为PIN码,从C++转换为Python或Javascript
- std::time_point from and to std::string
- 如何使用EM_JS从带有参数的C++调用javascript方法
- "No suitable conversion function from 'std::string' to 'const char *' exists"
- JavaScript 中的一等函数和 C++ 中的函数声明
- Webassembly from Javascript
- From JavaScript - swprintf
- Calling JavaScript from C++
- Call python from javascript