WASM with ffi arrays

Hi! If I have a JS array and want to pass it to Rust/WASM and return it (modified), how do I do that? When using arrays I only get undefined. :frowning: If it helps I can my code

https://stackoverflow.com/questions/52796222/how-to-pass-an-array-of-objects-to-webassembly-and-convert-it-to-a-vector-of-str

Does that help?

1 Like

hmm. Big thanks for your reply, @hellow! :slight_smile: But I would like to avoid wasm-bindgen. I seem to me that FFI is more small scale, more 'light-weight' than wasm-bindgen. Do you by any chance have and good ideas? I think it should be possible when I read the documentation, just can't figure out how... :frowning: :slight_smile:

Wasm-bindgen should be the lightest possible thing that works.

3 Likes

Ah, ok. Sorry! Did not know that. :slight_smile: I thought that it was way larger... will look into that then! Hmm... perhaps I thought that, because you can (right?) generate stuff (elements and so on) directly into the browser. This lib is only for the 'communication' in-between, I think. I am a bit new to this. :slight_smile: Really think it is very fun to play around with anyways! :slight_smile:

1 Like

yes, bindgen is purely for generating your own bindings between javascript and rust code;

you might have had it mixed up with web-sys which more or less wraps all web APIs using bindgen which is somewhat heavier but handy if you want to avoid writing javascript completely

2 Likes

nice! thank to you both for clearing this up for me! :slight_smile:

1 Like

@hellow Hello, This does help a bit. But in my case I want to return same Vec (with transformed values) from rust (wasm) to JS.

Please start a new thread, optionally linking to this one, instead of reviving a year old thread.

2 Likes

@alice Well, Not required.. I got the answer from Arbitrary Data with Serde - The `wasm-bindgen` Guide
Thanks!