Open twop opened 5 years ago
I'm also having this issue. Did you find a solution / workaround?
@alamastor Yes, I did, although it is not exactly pretty.
I used wasm-bindgen to expose a memory pointer through a function call. I have an example here:
wasm-bindgen allowed me to access these functions via the binding object: https://github.com/twop/ts-binary-types-workers-demo/blob/master/ts/worker.ts#L10 declared here: https://github.com/twop/ts-binary-types-workers-demo/blob/master/src/lib.rs#L39
I'm not sure if it covers your usecase but this is the approach I already used in several projects.
Yes, the normal way to access Wasm memory in JS is to export a function from Rust which returns a Uint8Array
.
If you want to access the entire Wasm memory, you can use the memory
function:
#[wasm_bindgen]
pub fn wasm_memory() -> JsValue {
wasm_bindgen::memory()
}
Now JS can use wasm_memory()
to access the entire Wasm linear memory.
Thanks @twop & @Pauan, that's what I needed, appreciate the help.
It also seems to work by adding '.wasm' to the memory import request. Eg:-
import { memory } from "../pkg/index_bg.wasm";
I want to get access to WASM module memory similar to https://rustwasm.github.io/book/game-of-life/implementing.html#rendering-to-canvas-directly-from-memory
From the tutorial:
when I try to do that
i got
But
index.js
file doesn't give access to memory :(Any workarounds?