-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
Referencing arrays in JS #804
Comments
Try this one: export function processF32Array(ptr: i32): void {
const val: f32 = 200
store<f32>(ptr + (0 << 2), val)
} |
Thanks. Tried it. It stays the same [100, 2, 3, 4]. |
Actually, if i make a slight change, I can see the array values get reset, so that indicates that it is not the same array I am working on in JS/WASM. JS:
Logs: |
You should invalidate your |
Ah, exactly what I just tried above :) |
I wonder if this is the part i misunderstood? WASM
|
No that part looks correct. |
I am not getting any kind of updates. Below I would expect the console.log to be [200] JS
WASM
SCRIPT
|
On the WASM side, it looks like I can do this: WASM
Now to figure out what to do on the JS side. |
Yeah, I forgot, you can't access direct to typed array by pointer, it has backing buffer, so you should use: export function processF32Array(arr: Float32Array, val: f32): void {
var index = 0;
store<f32>(arr.dataStart + (index << alignof<f32>), val);
} |
I guess before doing such low level things better read this part of documentation. Hope this help you |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I have looked at:
#105
#263
WebAssembly/design#1231
But I cannot make this thing work as I expect it to.
Given the below code, I would expect the console.logs to output [1, 2, 3, 4), [100, 2, 3, 4) then [200, 2, 3, 4). But what I see is [1, 2, 3, 4), [100, 2, 3, 4) then [100, 2, 3, 4). That indicates that my processF32Array is wrong. I tried different ideas, but none of them seems to reflect any changes on the JS side.
I could use a little help.
JS
WASM:
The text was updated successfully, but these errors were encountered: