You need to think of wasm as a completely separate environment so you cannot 
really share anything but `ptr UncheckedArray[uint8]` or `cstring` **from** the 
VM to the host since the VM and the Nim code have two completely different 
runtimes and data layout. The VM is also sandboxed so it cannot just get 
arbitrary pointers from the host and use them. It is best to make host 
procedures that take in the pointers and arguments and do the operations in 
native code. From my understanding of wasm if you want to write to a buffer and 
return it to the host you first need to call the VM's alloc procedure, then 
pass that returned `WasmPtr` to your wasm procedure. It then will write to it 
in the VM memory (Though this can all be done inside the VM of course and it 
just returns a `i32` which would be a `WasmPtr`). From there you need to 
convert that `WasmPtr` to a native pointer then you can extract the data how 
you need, be that allocating a `seq[uint8]` and copying the data to that or 
`cast[ptr UncheckedArray[uint8]]`. I do think I started on a general interface 
for converting from the VM representation to the host for the return value but 
I do not recall what happened to that.

Reply via email to