killercup / wasm-experiments

Please don't use this! Check out this instead:
https://rustwasm.github.io/
MIT License
62 stars 11 forks source link

Support JsString->{&str, String}->JsString #3

Open killercup opened 7 years ago

killercup commented 7 years ago

Approach:

  1. alloc string length, put in utf-8 data
  2. alloc 2/3 words, put in (data, len) or (data, len, cap)
killercup commented 7 years ago

Tried that in

https://github.com/killercup/wasm-experiments/blob/724217f09c9b9cfc5c177989a8b4a73feda36de6/src/wasm-io.js#L27-L34

and

https://github.com/killercup/wasm-experiments/blob/724217f09c9b9cfc5c177989a8b4a73feda36de6/src/wasm-io.js#L65-L73

but the data I get is not a (ptr, len) I can understand.

Also, a fn that return a fat point/String does so by writing to an out argument, i.e., you pass in a ptr to an allocation the size of the return value on the stack. So, we need to extend wrap to be able to deal with adding this argument to the WASM call.