Skip to main content

Install

Stof is a library you add to your app: an npm package, a Python package, or a Rust crate. There's also a command-line tool for running and testing .stof files. You don't need to install anything to learn the language: every example in these docs has a Run button, and the playground runs in your browser.

Each tab below runs the same document:

hello.stof
name: 'Stof'

fn greet() -> str {
`Hello, ${self.name}!`
}

#[main]
fn main() {
pln(self.greet());
}
npm i @formata/stof

@formata/stof on npm

index.ts
import { StofDoc } from '@formata/stof';

const doc = await StofDoc.new(`
name: 'Stof'
fn greet() -> str { \`Hello, \${self.name}!\` }

#[main]
fn main() { pln(self.greet()); }
`);

await doc.run(); // Hello, Stof!
console.log(await doc.call('greet')); // Hello, Stof!

In JavaScript, pln writes to console.log and err to console.error. To send a document's output somewhere else, replace them with your own functions: doc.lib('Std', 'pln', (...args) => ...). Usually you'll call functions and use what they return instead.

Browsers and Bundlers​

StofDoc.new loads Stof's WebAssembly automatically in Node.js and in browsers without a bundler. A bundler like Vite or webpack changes how files are loaded, so give it the file yourself, once, before creating documents:

Vite
import { initStof } from '@formata/stof';
import stofWasm from '@formata/stof/wasm?url';

await initStof(stofWasm);
Other bundlers (webpack, Rollup, ...)
import { initStof } from '@formata/stof';
import stofWasm from '@formata/stof/wasm';

await initStof(await stofWasm());

Webpack doesn't load .wasm files on its own. If that import fails to parse, add a rule that treats them as files:

webpack.config.js
module: {
rules: [{ test: /\.wasm$/, type: 'asset/resource' }]
}

Editor Support​

The Stof extension for VS Code highlights .stof files, and with the CLI installed it also shows errors as you type, goes to definitions, completes names, and renames across files. See Tools.

Teaching an AI Model Stof​

Models can read and write Stof already, since it looks like JSON and JavaScript. To make them reliable, give your agent the Stof skill: a short guide to the language and the mistakes to avoid, with the library references in stof.zip.