You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rhai is an embedded scripting language and evaluation engine for Rust that gives a safe and easy way
to add scripting to any application.
Targets and builds
All CPU and O/S targets supported by Rust, including:
WebAssembly (WASM)
no-std
Minimum Rust version 1.66.0
Versions
The ahash crate that Rhai depends on has a breaking change since version 0.8.12 which bumps getrandom to version 0.3, braking certain no-std and WASM builds.
Version 1.23.5: Use this version when building for no-std or WASM.
Version 1.23.6: This is the main version for std builds.
Standard features
Simple language similar to JavaScript+Rust with dynamic typing.
Fairly efficient evaluation - 1 million iterations in 0.14 sec on a single-core 2.6 GHz Linux VM running this script.
Freely pass Rust values into a script as variables/constants via an external Scope - all clonable Rust types are supported; no need to implement any special trait. Or tap directly into the variable resolution process.
Don't Panic guarantee - Any panic is a bug. Rhai subscribes to the motto that a library should never panic the host system, and is coded with this in mind.
Sand-boxed - the scripting engine, if declared immutable, cannot mutate the containing environment unless explicitly permitted.
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.constTARGET=28;constREPEAT=5;constANSWER=317_811;fnfib(n){ifn<2{n}else{fib(n-1)+fib(n-2)}}print(`Running Fibonacci(${TARGET}) x ${REPEAT} times...`);print("Ready... Go!");letresult;letnow=timestamp();fornin0..REPEAT{result=fib(TARGET);}print(`Finished. Run time = ${now.elapsed} seconds.`);print(`Fibonacci number #${TARGET} = ${result}`);ifresult!=ANSWER{print(`The answer is WRONG! Should be ${ANSWER}!`);}
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.