How to return an array of numbers from a function in asm.js?

Viewed 1079

I'm sure I could eventually figure this out, but the documentation is a bit verbose and I think this ought to be a common question about asm.js.

Here goes:

Suppose that I have a function that looks like this:

function computeSquares() {
    var i, array = [];
    for(i = 0; i < 100; i++) {
        array.push(i * i);
    }
    return array;
}

The above function computes the square of the integers from 0 to 99 and returns an array containing the results.

I would like to write a function like this in asm.js that returns an object containing the 100 square values. If I've read the documentation, I'm supposed to use the ArrayBuffer object, but I'm a bit confused about how to do it.

Please illuminate me by giving an example of how to code this with asm.js.

3 Answers
Related