Globals
The globals section is where we can import and export values in and out of WebAssembly modules. In a WebAssembly module, you can import either mutable or immutable values from JavaScript. Additionally, WebAssembly also supports wasmValue
, an internal immutable value inside the WebAssembly module itself.
Let's create a file called globals.wat
and add the following contents to it:
$ touch globals.wat (module (global $mutableValue (import "js" "mutableGlobal") (mut i32)) (global $immutableValue (import "js" "immutableGlobal") i32) (global $wasmValue i32 (i32.const 10)) (func (export "getWasmValue") (result i32) (global.get $wasmValue)) (func...