In Guile Hoot how to pass arrays between JS Runtime and Guile?

I am writing a custom game engine using guile hoot. I want to pass a Guile f32 vector to javascript as an array, however the WASM Specification does not even support arrays as an type. Moreover, other wasm implementations implement this feature by accessing the wasm’s Linear Memory directly, and reading the array from a pointer and length passed as function parameters.

Can you guys help me figure this out?

1 Like

Hi @binarydigitz01,

The Wasm spec does support array types, actually! Arrays are one of the heap types. In Hoot, we use a packed array, (array i8) to be precise, to store Scheme bytevectors. Hoot does not use linear memory for Scheme objects because there would be no automatic garbage collection if we did.

Heap-allocated packed arrays have a notable limitation at present: they cannot be viewed as a TypedArray from JavaScript; they’re opaque. So, to answer your question: you have to copy element by element right now. Not great, but that’s the situation. An example of this can be seen in Hoot’s stream module where chunks (Uint8Arrays) are copied byte-by-byte to and from bytevectors.

I wrote a blog post on this subject last year that you might be interested in.

Hope this helps!