Skip to content

WASM

Early Alpha - Expect Breakage

The WASM build is alpha quality. The API isn't stable yet and there are known bugs; despite the rough edges it is usable and useful already.

Take it for a spin!

Feather compiles to WebAssembly, allowing you to embed a TCL interpreter in Node.js applications and web browsers.

Installation

Download these files:

Node.js

javascript
import { createFeather } from './feather.js';

const feather = await createFeather('./feather.wasm');
const interp = feather.create();

// Register host commands
feather.register(interp, 'puts', (args) => {
  console.log(args.join(' '));
});

// Evaluate TCL code
const result = feather.eval(interp, 'expr {2 + 2}');
console.log(result); // "4"

// Clean up
feather.destroy(interp);

Browser

html
<script type="module">
import { createFeather } from './feather.js';

const feather = await createFeather('/feather.wasm');
const interp = feather.create();

feather.register(interp, 'puts', (args) => {
  document.body.innerText += args.join(' ') + '\n';
});

feather.eval(interp, 'puts "Hello from Feather!"');
</script>

How Not to Suffer

Remember, Feather is a thin glue layer to expose existing functionality of your application.

Do:

  • keep all state you need to manage in JavaScript,
  • keep your custom commands short: they should parse arguments and call your application code

Don't:

  • manage state in Feather,
  • write complicated custom commands: these are thin entrypoints only

Try It

Output

API Reference

createFeather(wasmSource)

Creates a Feather runtime. Returns a promise.

  • wasmSource - Path to WASM file, URL, ArrayBuffer, or Response

feather.create()

Creates a new interpreter. Returns an interpreter ID.

feather.eval(interpId, script)

Evaluates TCL code. Returns the result as a string. Throws on error.

feather.register(interpId, name, fn)

Registers a host command. fn receives an array of strings.

To signal an error, throw an exception:

Output

feather.registerType(interpId, typeName, typeDef)

Registers a foreign object type. Use with createForeign to create instances that become callable commands:

Output

feather.destroy(interpId)

Destroys an interpreter and frees resources.