Install
Every tab below runs the same document — pick whichever host fits what you're building. If you'd rather not install anything yet, every concept page from here on has a Run button built right into the page; nothing to set up.
str message: "Hello, Stof!"
fn greet() -> str {
`${self.message} Data and logic, together.`
}
#[main]
fn main() {
pln(self.greet());
}
- TypeScript
- Python
- Rust
- CLI
Install:
npm i @formata/stof
Run:
import { stofAsync } from '@formata/stof';
const doc = await stofAsync`
message: "Hello, Stof!"
fn greet() -> str {
\`\${self.message} Data and logic, together.\`
}
#[main]
fn main() {
pln(self.greet());
}
`;
// Bridge Stof's pln(...) to your host's console
doc.lib('Std', 'pln', (...args: unknown[]) => console.log(...args));
await doc.run();
Hello, Stof! Data and logic, together.
Initializing in a Browser or Bundler
stofAsync above works with zero setup in Node, Deno, and Bun — Stof's WASM binary loads automatically. A bundler processes imports differently, so that auto-detection doesn't always apply — pick whichever pattern matches your setup:
import { initStof } from '@formata/stof';
import stofWasm from '@formata/stof/wasm?url';
await initStof(stofWasm);
import { initStof } from '@formata/stof';
import stofWasm from '@formata/stof/wasm';
await initStof(await stofWasm());
Webpack specifically doesn't handle a raw .wasm import out of the box — if that import throws a parse error, add a rule telling webpack to treat .wasm files as a binary asset instead of trying to parse them as JavaScript:
module: {
rules: [{ test: /\.wasm$/, type: 'asset/resource' }]
}
Call initStof() once, before creating any document. After that, the lower-level StofDoc constructor works the same way stofAsync and StofDoc.parse(...) do elsewhere on this page — those two just handle this step for you automatically in Node, Deno, and Bun:
import { initStof, StofDoc } from '@formata/stof';
await initStof();
const doc = new StofDoc();
doc.parse(`
name: "Alice"
age: 30
fn greet() -> str {
'Hello, ' + self.name
}
`);
console.log(await doc.call('greet')); // "Hello, Alice"
console.log(doc.get('age')); // 30
Install:
pip install stof
Run:
from pystof import Doc
doc = Doc()
doc.parse("""
str message: "Hello, Stof!"
fn greet() -> str {
`${self.message} Data and logic, together.`
}
#[main]
fn main() {
pln(self.greet());
}
""")
doc.run()
Hello, Stof! Data and logic, together.
Add to Cargo.toml:
[dependencies]
stof = "0.9.*"
Run:
use stof::model::Graph;
fn main() {
let mut graph = Graph::default();
graph.parse_stof_src(r#"
str message: "Hello, Stof!"
fn greet() -> str {
`${self.message} Data and logic, together.`
}
#[main]
fn main() {
pln(self.greet());
}
"#, None).unwrap();
graph.run(None, true).unwrap();
}
Hello, Stof! Data and logic, together.
Install via Cargo:
cargo install stof-cli
Don't have Rust? Install it here — Cargo comes with it.
Run:
stof run hello.stof
Hello, Stof! Data and logic, together.
Using VS Code? The Stof extension adds syntax highlighting for .stof files — search "Stof" in the extensions tab, or install it directly from the marketplace link.