wasm-ffi
wasm-ffi copied to clipboard
What about ffi with AssemblyScript?
Hi DeMille. You did a great stuff with integration C/C++ and rust. What do you think add also dcode's AssemblyScript?
AssemblyScript looks pretty sweet! I just started playing around with it and I think support could be added pretty easily. I just pushed a branch to work on it.
The main issues I've noticed are strings and arrays, which have to be done differently than c/rust. I added an option field in the Wrapper class for assemblyscript to change that behavior. Classes seem work fine if you just treat them like a C struct.
You can check out the changes I made: https://webassembly.studio/?f=tc114km3bvh
I haven't really dived too deep into it, are there other language features I'm missing?
Cool! Are you try Array instead ArrayBuffer? AssemblyScript support global arrays:
const globArray: i32[] = [1, 2, 3];
export function getFirstElement(): i32 {
return globArray[i];
}
as well as alloc in heap arrays:
export function createArray(len: i32): f32[] {
var arr = new Array<f32>(1);
arr.push(1.0);
arr.push(NaN);
return arr;
}
That might make more sense. I did the arraybuffers because those seem like they're the most basic element ('normal' arrays are backed by them).
I didn't realize arrays are typed in AssemblyScript though! That's basically an arraybuffer with some extra methods here. I think that should be an easy change. I'll try that.