|
|
@ -0,0 +1,38 @@ |
|
|
|
canvas = document.getElementById("canvas"); |
|
|
|
ctx = canvas.getContext("2d"); |
|
|
|
|
|
|
|
function get_string(memory, pointer, size) |
|
|
|
{ |
|
|
|
var array = new Int8Array(memory.buffer, pointer, size); |
|
|
|
return (new TextDecoder()).decode(array); |
|
|
|
} |
|
|
|
|
|
|
|
function paint(memory, pointer, width, height) |
|
|
|
{ |
|
|
|
array = new Uint8ClampedArray(memory.buffer, pointer, 4 * width * height); |
|
|
|
data = new ImageData(array, width, height); |
|
|
|
ctx.putImageData(data, 0, 0); |
|
|
|
} |
|
|
|
|
|
|
|
fetch("wt.wasm").then(response => response.arrayBuffer()).then(bytes => |
|
|
|
{ |
|
|
|
var memory; |
|
|
|
WebAssembly.instantiate(bytes, { env: |
|
|
|
{ |
|
|
|
console_log: function(str, len) |
|
|
|
{ |
|
|
|
console.log(get_string(memory, str, len)); |
|
|
|
}, |
|
|
|
extern_paint: function(pointer, width, height) |
|
|
|
{ |
|
|
|
paint(memory, pointer, width, height); |
|
|
|
} |
|
|
|
} }).then(mod => |
|
|
|
{ |
|
|
|
memory = mod.instance.exports.memory; |
|
|
|
mod.instance.exports.entrypoint(); |
|
|
|
mod.instance.exports.paint_red(canvas.width, canvas.height); |
|
|
|
} |
|
|
|
) |
|
|
|
}); |
|
|
|
|