WebAssembly image dithering example

Radu void at null.pt
Fri Aug 3 11:42:18 UTC 2018


On Friday, 3 August 2018 at 11:34:23 UTC, Kagamin wrote:
> Something like
>
> ```wasm.d
> extern(C):
>
> static shared size_t len;
>
> const(char)* towastr(string s)
> {
>     len=s.length;
>     return s.ptr;
> }
>
> const(char)* echo()
> {
>     return towastr("Hello from WASM!");
> }
> ```
>
> ```wasm.js
> ...
> function wastr(ptr)
> {
>     var buffer = new Uint8Array(linearMemory.buffer, ptr, 
> wasmInstance.exports.len);
>     var msg = '';
>     for (var i=0; i < buffer.length; i++) {
>         msg += String.fromCharCode(buffer[i]);
>     }
>     return msg;
> }
> var str=wastr(wasmInstance.exports.echo());
> console.log(str);
> ```

It wasn't a question :) it was an example, the way I did mine - 
you pass the length to the Js side, no need to mess with statics.


More information about the digitalmars-d-ldc mailing list