Wasm Reference
  • Welcome
  • Nodejs WAT Compiler
  • Types
    • Functions
    • Globals
    • Linear Memory
    • Tables
    • Numbers
    • Text
  • Structures
    • IF
    • LOOP
  • Algorithms
    • Hello World
    • Estimate Pi
  • Maths Helper Algorithms
    • Pseudorandom Number Generator
    • Factorial
    • Dist
    • Map
    • Fract
    • RemF or ModF
    • Round
    • Clamp
    • Mix
    • Pow
    • Approx Sin
    • Approx Cos
    • Approx Tan
    • ToRad and ToDeg
Powered by GitBook
On this page
  • Global
  • Global Import Example

Was this helpful?

  1. Types

Globals

Global

// define global
(global $g (mut i32) (i32.const 0))
  
// get global
(get_global $g)

// set global
(set_global $g (i32.const 10))

Global Import Example

const global = new WebAssembly.Global({value:'i32', mutable:true}, 0);

var importObject = { js: { global: global} };

WebAssembly.instantiate(wasmModule.toBinary({}).buffer, importObject).then(function(res) {
    
  });
// import
(global $g (import "js" "global") (mut i32))
PreviousFunctionsNextLinear Memory

Last updated 5 years ago

Was this helpful?