-
I can define a host function that uses module-defined memory like this: linker.func_wrap("env", "hline", |mut caller: C, x: i32, y: i32, len: u32| {
let mem = match caller.get_export("memory") {
Some(wasmi::Extern::Memory(mem)) => mem,
_ => panic!("memory not found"),
};
let (data, bridge) = mem.data_and_store_mut(&mut caller);
let frame_buf = FrameBuf::from_memory(data);
bridge.wasm4_hline(frame_buf, x, y, len)
})?; However, if I define a memory on the host side: let mem_type = wasmi::MemoryType::new(1, Some(1)).unwrap();
let mem = wasmi::Memory::new(&mut store, mem_type).unwrap();
linker.define("env", "memory", mem).unwrap(); I can't simply use let memory = match linker.get(&mut store, "env", "memory") {
Some(wasmi::Extern::Memory(memory)) => memory,
_ => panic!("memory not found"),
}; However, if I try to do the same inside of a
Is there a way to get access to the memory inside the linker from a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Wasm types such as Thus you can simply copy the |
Beta Was this translation helpful? Give feedback.
Wasm types such as
Memory
,Table
,Global
andFunc
are deliberatelyCopy
andClone
types and thus cheap to clone. This works since they are just fancy, typed indices into some tables into theStore
.Thus you can simply copy the
mem
before passing it to theLinker
in one of your examples and even putmem
into theHostState
to access it via host functions amongst others.