wasm/js_wasm32 Web

Overview

Odin js_wasm32 example

This is an example of how to build an Odin program using the js_wasm32 target. The example features a website that can call an Odin procedure.

Building

Run build.bat (Windows) or build.sh (mac / Linux).

This builds the WASM module and also copies odin.js from the core Odin library as it's required for a js_wasm32 build.

Running

You need to run a local webserver in the web directory in order to serve the site. There are few, simple options for this.

  • Navigate to the web directory.
cd web
  • Run a webserver.
# If you have Python installed.
python -m http.server
# If you have Node.js installed.
npx http-server -p 8000 .

Code

main.odin ¶
13 linesSource

1package main
2
3// The build will fail without the required `main` function,
4// though we won't use it at all in this example.
5main :: proc() {}
6
7// This is the function we'll use in the browser.
8// Add the @export() attribute to ensure that the function is
9// available in our WASM module.
10@(export)
11add_numbers :: proc(a: i32, b: i32) -> i32 {
12	return a + b
13}

To Build and Run 4