- 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.
- Facebook Application Development with Graph API Cookbook
- 自制編譯器
- Scala Design Patterns
- 編程珠璣(續)
- 精通搜索分析
- 深入RabbitMQ
- Unity 5 for Android Essentials
- 用戶體驗增長:數字化·智能化·綠色化
- Learning OpenStack Networking(Neutron)(Second Edition)
- PHP編程基礎與實例教程
- 深度學習原理與PyTorch實戰(第2版)
- Flink核心技術:源碼剖析與特性開發
- FusionCharts Beginner’s Guide:The Official Guide for FusionCharts Suite
- 面向物聯網的Android應用開發與實踐
- Swift編程實戰:iOS應用開發實例及完整解決方案