ashtonmeuser / godot-wasm

Interact with WebAssembly modules from Godot
https://github.com/ashtonmeuser/godot-wasm/wiki
MIT License
193 stars 11 forks source link

External memory support #51

Closed ashtonmeuser closed 1 year ago

ashtonmeuser commented 1 year ago

Breaking change in the following ways.

  1. StreamPeerWasm class renamed to WasmMemory
  2. Module memory accessed via memory property instead of stream
  3. Structure of inspect dictionary changed to include nested memory dictionary

Adds the following behaviour.

  1. Functional external memory with WasmMemory.new()
  2. Grow external memory with memory.grow()
  3. All modules and memories share a single Wasm runtime engine and store
  4. Import memory on module instantiation
  5. Inspect module memory with memory.inspect()

This PR allows for importing external memory. This allows multiple modules to share memory space. External memory can be created with WasmMemory.new()and grown with memory.grow(N_PAGES) where N_PAGES represents the number of pages to grow the memory space by. Per Wasm specs, memory pages are 65535 bytes.

External memory is provided to a module as an import as follows.

var wasm = Wasm.new()
var memory = WasmMemory.new()
memory.grow(100)
var imports = { "memory": memory }
wasm.load(bytecode, imports)
fire commented 1 year ago

What can I do to review this?

ashtonmeuser commented 1 year ago

Hey there! Thanks for the offer to help! This PR will be on ice for just a little longer while I 1) backport to the Godot 3.x branch and 2) update docs.

I should be able to find some time this weekend. This is a big one that I'm quite excited for 🙂

fire commented 1 year ago

Horray