官术网_书友最值得收藏!

Wasm to JavaScript

The upper-right pane in the following screenshot contains some JavaScript code to compile the Wasm that was generated in the previous step. The wasmCode was generated when the build finished, so it should be available automatically. Rather than use the instantiate() method, WasmFiddle creates a compiled WebAssembly.Module instance and passes that into the constructor of a new WebAssembly.Instance. The wasmImports object is currently empty, although we could pass in a WebAssembly.Memory and WebAssembly.Table instance if desired:

JavaScript code calling the C function from the compiled Wasm module

The final line of JavaScript prints the result of addTwo() to the output in the lower-right pane when passed the number 2. The log() method is a custom function that ensures the output is printed to the lower-right pane (the number 4). Note how the JavaScript code interacts with wasmInstance. The addTwo() function is called from the instance's exports object. Although this was a contrived example, it demonstrates the steps C or C++ code goes through before it can be used by JavaScript as a Wasm module.

主站蜘蛛池模板: 荔波县| 曲靖市| 双流县| 清河县| 柞水县| 镇江市| 鲜城| 邻水| 莎车县| 太和县| 嵩明县| 厦门市| 酒泉市| 松阳县| 永清县| 邯郸市| 中阳县| 盖州市| 崇仁县| 闵行区| 佛坪县| 翼城县| 平顶山市| 高要市| 中西区| 新蔡县| 孝感市| 精河县| 新乡市| 昂仁县| 义马市| 宜章县| 辛集市| 沧源| 太仓市| 息烽县| 勃利县| 沂水县| 治多县| 江津市| 徐水县|