- 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.
- HTML5+CSS3+JavaScript從入門到精通:上冊(cè)(微課精編版·第2版)
- Spring 5.0 By Example
- 算法精粹:經(jīng)典計(jì)算機(jī)科學(xué)問題的Python實(shí)現(xiàn)
- Visual Basic程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)(第4版)
- 差分進(jìn)化算法及其高維多目標(biāo)優(yōu)化應(yīng)用
- Building a Quadcopter with Arduino
- Java系統(tǒng)化項(xiàng)目開發(fā)教程
- Unity 2018 Shaders and Effects Cookbook
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- Learning Material Design
- Visual Basic程序設(shè)計(jì)習(xí)題與上機(jī)實(shí)踐
- Mudbox 2013 Cookbook
- HTML5移動(dòng)前端開發(fā)基礎(chǔ)與實(shí)戰(zhàn)(微課版)
- 精益軟件開發(fā)管理之道
- Learning Apache Thrift