-
-
Notifications
You must be signed in to change notification settings - Fork 673
how to create UInt8Array in AssemblyScript and return it to caller #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@msbasanth This code wouldn't valid for pure Typescript. Uint8Array hasn't
|
I modified accordingly @MaxGraey, now I have one warning,
How should I make memory manager available? Does this warning will create any runtime problem?
|
No, you just need import one of memory allocators. import "allocator/arena"; |
Yes @MaxGraey after adding memory allocator that warning also gone. Now I could generate the d.ts, wasm and .map files from my AssemblyScript. my optimized.d.ts look like this: This is my function signature: In both these cases asbuild generated 'function decodeRLE(encodedBuffer: u32): u32' in optimize.d.ts. Whether I am missing or need to do for correcting the function signature. |
When returning an array from WASM to JS, what you'll get on the JS side is the pointer (offset in memory), to a structure with the following layout. To retreive the values on the JS side, you'd read the |
Thanks for the quick reply @dcodeIO the returned pointer to the array (number it showed is 16) I tried reading buffer but it is undefined.
These are the two AS functions I am trying to access,
When I tried to access |
|
Thanks for the explanation, still unable to read the This is my WebAssembly fetch code:
My observations:
How can I make F64 available for module? |
Well, if I'm not totally off, your initial memory is set to 1. ((80 + 0xffff) & ~0xffff) === 65536 And I don't see why you need such a bit-dancing calc for the memory :) |
So, as I was in a total lack of better understanding, I asked on the WebAssembly design repo. And heureka... here we go!! :))) |
That's OK, the initial memory is defined in terms of 64KiB pages. That calculation is rounding |
Example code (using current impl. by @dcodeIO): https://github.com/kyr0/assemblyscript-js-wasm-interop-example |
@kyr0 the sample worked fine which showed how we can share an array to WASM and get the array modified. This simplified the passing arrays between JS and WASM. The same sample I am trying to run in browser (Angular) application. Instead of using loader.instantiateBuffer I used loader.instantiateStreaming.
I am getting this error:
Is it the right way I am using loader.instantiateStreaming? Regards |
Seems there's a limitation on |
Just to be clear, this is a Chrome-only restriction, AFAIK other browsers allow it. But to be safe, it's best to use |
There is a limitation on WebAssembly.Instance for Chrome. I switched to firefox for my testing and I could see below code worked fine.
|
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I am using AssemblyScript to convert my RLE decode code written in TypeScript to WebAssembly.
This is what I did,
ERROR AS100: Operation not supported.
var decodedBuffer = [];
in assembly/index.ts(97,24)
ERROR TS2339: Property 'push' does not exist on type 'i32'.
decodedBuffer.push(myvalue);
in assembly/index.ts(116,24)
ERROR AS200: Conversion from type 'f64' to 'i32' requires an explicit cast.
pos+=cmd;
in assembly/index.ts(119,13)
I would like to know how we can create a array (UInt8Array) in AssemblyScript? I aso want to return the created array back to consumers of my WASM. So that I can move the decode code to WASM.
Thanks
Basanth
The text was updated successfully, but these errors were encountered: