- Learn WebAssembly
- Mike Rourke
- 178字
- 2021-08-13 15:38:55
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:
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.
- Visual Studio 2012 Cookbook
- Visual C++實例精通
- Python數(shù)據(jù)可視化之Matplotlib與Pyecharts實戰(zhàn)
- PySpark Cookbook
- Protocol-Oriented Programming with Swift
- Instant Lucene.NET
- 圖數(shù)據(jù)庫實戰(zhàn)
- Building Wireless Sensor Networks Using Arduino
- Python數(shù)據(jù)可視化之美:專業(yè)圖表繪制指南(全彩)
- Clojure High Performance Programming(Second Edition)
- 數(shù)據(jù)結(jié)構(gòu):Python語言描述
- Spring Data JPA從入門到精通
- Flutter之旅
- 前端程序員面試算法寶典
- jBPM6 Developer Guide