README.md
Rhai is an embedded scripting language and evaluation engine for Rust that gives a safe and easy way to add scripting to any application.
no-stdAs of this version, stdweb is no longer supported for WASM builds
because of changes to getrandom starting from version 0.3.
Scope - all clonable Rust types are supported; no need to implement any special trait. Or tap directly into the variable resolution process.Decimal), strings, Unicode characters, arrays (including packed byte arrays) and object maps.unsafe code (yes there are some for performance reasons).smallvec, thin-vec, num-traits, once_cell, ahash, bitflags and smartstring.Send + Sync (via the sync feature).serde feature).The scripts subdirectory contains sample Rhai scripts.
Below is the standard Fibonacci example for scripting languages:
// This Rhai script calculates the n-th Fibonacci number using a
// really dumb algorithm to test the speed of the scripting engine.
const TARGET = 28;
const REPEAT = 5;
const ANSWER = 317_811;
fn fib(n) {
if n < 2 {
n
} else {
fib(n-1) + fib(n-2)
}
}
print(`Running Fibonacci(${TARGET}) x ${REPEAT} times...`);
print("Ready... Go!");
let result;
let now = timestamp();
for n in 0..REPEAT {
result = fib(TARGET);
}
print(`Finished. Run time = ${now.elapsed} seconds.`);
print(`Fibonacci number #${TARGET} = ${result}`);
if result != ANSWER {
print(`The answer is WRONG! Should be ${ANSWER}!`);
}
See The Rhai Book for details on the Rhai scripting engine and language.
An Online Playground is available with syntax-highlighting editor, powered by WebAssembly.
Scripts can be evaluated directly from the editor.
Licensed under either of the following, at your choice:
Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion in this crate, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.