WebAssemblyでScratchプラグインを作ろう!
さっきの「hello world」に再挑戦
<script type="module">
import {WASI, File, OpenFile, ConsoleStdout}
from 'https://cdn.jsdelivr.net/npm/@bjorn3/[email protected]/+esm'
const fds = [
new OpenFile(new File([])),
ConsoleStdout.lineBuffered(msg => console.log(`[WASI stdout] ${msg}`)),
ConsoleStdout.lineBuffered(msg => console.warn(`[WASI stderr] ${msg}`)),
];
const wasi = new WASI([], [], fds);
const obj = {
"wasi_snapshot_preview1": wasi.wasiImport,
};
const wasm = await WebAssembly.compileStreaming(fetch("hello2.wasm"));
const instance = await WebAssembly.instantiate(wasm, obj);
wasi.start(instance);
</script>