Crate rhai [] [src]

Rhai - embedded scripting for Rust

Rhai is a tiny, simple and very fast embedded scripting language for Rust that gives you a safe and easy way to add scripting to your applications. It provides a familiar syntax based on JS and Rust and a simple Rust interface. Here is a quick example. First, the contents of my_script.rhai:

fn factorial(x) {
    if x == 1 { return 1; }
    x * factorial(x - 1)
}

compute_something(factorial(10))

And the Rust part:

use rhai::{FnRegister, Engine};
 
fn compute_something(x: i64) -> bool {
    (x % 40) == 0
}
 
let mut engine = Engine::new();
engine.register_fn("compute_something", compute_something);
assert!(engine.eval_file::<bool>("my_script.rhai").unwrap());

Check out the README on github for more information!

Structs

Engine

Rhai's engine type. This is what you use to run Rhai scripts

Enums

EvalAltResult

Traits

FnRegister

A trait used for registering functions to an Engine Currently, Rhai supports functions with up to 6 parameters

Type Definitions

Scope

A type containing information about current scope. Useful for keeping state between Engine runs