tessi / wasmex

Execute WebAssembly from Elixir
MIT License
528 stars 27 forks source link

Get and Set Globals #540

Closed RoyalIcing closed 3 months ago

RoyalIcing commented 3 months ago

Add Wasmex.Instance.get_global_value/3 and Wasmex.Instance.set_global_value/4 to read and write globals.

I don’t believe languages like Rust or C allow exporting globals, but in raw WebAssembly this is very much possible:

(module
  (global (export "meaning_of_life") i32 (i32.const 42))
  (global (export "count") (mut i64) (i64.const 0))
)

I’ve followed what appears to be the convention of returning string errors. If you like I can make them atoms like {:error, :not_found} or {:error, :immutable}.