Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Hello, World!" #7

Open
monoclex opened this issue Sep 4, 2020 · 1 comment
Open

"Hello, World!" #7

monoclex opened this issue Sep 4, 2020 · 1 comment

Comments

@monoclex
Copy link

monoclex commented Sep 4, 2020

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!".

@munrocket
Copy link

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants