Next: NodeJS deployment, Up: Deployment [Contents][Index]
On the client-side web, JavaScript is the host environment for Wasm
modules and the
WebAssembly
API is used to load and run them. Hoot includes a JavaScript library,
reflect.js (see JavaScript reflection) that wraps the
WebAssembly API and furthermore can inspect Scheme values and
call Scheme procedures. This chapter documents deploying Hoot
artifacts and using the reflection API to run Scheme in the browser.
Running Hoot programs inside a web browser requires some support
libraries. The hoot compile command has a convenient flag
to copy those support files next to the Wasm binary when compiling:
hoot compile --bundle -o hello.wasm hello.scm
After this command runs, there will be files such as reflect.js and reflect.wasm in addition to hello.wasm in the current directory.
A bit of JavaScript code is needed to bootstrap a Scheme program using the reflect.js support library (see JavaScript reflection). For example, here’s an example boot.js file that runs the Scheme program hello.wasm and prints the return values:
window.addEventListener("load", async () => {
const results = await Scheme.load_main("/hello.wasm");
console.log(results);
});
The Scheme namespace is defined in reflect.js.
See JavaScript reflection for more information.
To run boot.js on a web page, add <script> tags for it
and reflect.js:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/reflect.js"></script>
<script type="text/javascript" src="/boot.js"></script>
</head>
<body>
<h1>Hello, Hoot!</h1>
</body>
</html>