postscriptum
A multi-interpreted-language scripting engine for Rust.
postscriptum lets you embed scripting into your Rust application and register
Rust functions callable from the scripts. It is Bevy-free and works on
native and WASM targets.
Currently two backends are implemented:
| Language | Native | WASM |
|---|---|---|
| Rhai | rhai (pure Rust) | rhai (pure Rust) |
| Python | pyo3 | Pyodide (JS interop) |
Quickstart
The shortest possible example — create an engine and evaluate a script:
use ;
let mut engine = get_engine;
assert_eq!;
# Ok::
See QUICKSTART.md for the full guide: the core concept,
registering Rust functions callable from scripts (FunctionBundle,
add_*_fn0..4), keeping interpreter state between runs, sharing engines across
threads (ThreadSafeEngine), and native vs WASM notes.
Examples
Runnable examples live in examples/:
basic_rhai— evaluate a Rhai script and call a registered Rust function.basic_python— the same with the Python backend.thread_safe— share a singleThreadSafeEngineacross threads.
Run them from the crate root, e.g. cargo run --example basic_rhai
(basic_python needs the python feature, which is on by default).
Features
rhai— enables the Rhai backend (pure Rust, always available). (default)python— enables the native Python backend viapyo3(default); on WASM this is a no-op, since the WASM Python backend useswasm-bindgen/Pyodide.wasm-python— marker for the WASM Python (Pyodide) backend.native-python— convenience alias forpython.
How it works
- [
ScriptEngine] — the core trait:fn eval(&mut self, &str) -> Result<String>. Each backend (RhaiEngine,PythonEngine) implements it and keeps interpreter state betweenevalcalls. - [
ThreadSafeEngine] — aClonewrapper aroundArc<Mutex<Box<dyn ScriptEngine>>>that makes the (non-Send) Python engine usable across threads. - [
FunctionBundle] — the language-tagged way to expose Rust functions to scripts (add_rhai_fn0..4/add_python_fn0..4), with per-language registration into the engine. - [
EngineType] —Rhai | Python(extensible).
License
MIT OR Apache-2.0