Open monoclex opened 4 years ago
It's not WASI, but here hello world
example in browser. Also I recommend to check reference types example #15 if you want to write console.log() directly in AssemblyScript
//main.ts
export function hello(s: string): string {
return "Hello " + s;
}
//main.js
import * as AsBind from '../node_modules/as-bind/dist/as-bind.esm.js';
async function init() {
const instance = await AsBind.instantiate(fetch('../build/b.wasm'), imports);
const wasm = instance.exports;
console.log(wasm.hello('world!'));
};
init();
//package.json
"scripts": {
"build": "asc main.ts --exportRuntime --transform as-bind -b b.wasm",
"start": "servez"
},
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<title>Test</title>
</head>
<body>
<script type="module" src="main.js"></script>
</body>
</html>
Perhaps one of the more simpler requests of an example, which has a complicated solution. If WASI is implemented, this would be a call to
fd_write
. If they aren't, then this would be one hell of a "Hello, World!".