2017-10-28 22:33:00 +02:00
|
|
|
//! # 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`:
|
|
|
|
//!
|
|
|
|
//! ```rust_todo_disable_testing_enable_highlighting
|
|
|
|
//! fn factorial(x) {
|
|
|
|
//! if x == 1 { return 1; }
|
|
|
|
//! x * factorial(x - 1)
|
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! compute_something(factorial(10))
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! And the Rust part:
|
|
|
|
//!
|
|
|
|
//! ```rust
|
|
|
|
//! 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);
|
|
|
|
//! # // Very ugly hack incoming, TODO
|
|
|
|
//! # use std::fs::{File, remove_file};
|
|
|
|
//! # use std::io::Write;
|
|
|
|
//! # let mut f = File::create("my_script.rhai").unwrap();
|
2017-10-30 08:53:11 +01:00
|
|
|
//! # let _ = write!(f, "{}", "fn f(x) { if x == 1 { return 1; } x * f(x-1) } compute_something(f(10))");
|
2017-10-28 22:33:00 +02:00
|
|
|
//! assert!(engine.eval_file::<bool>("my_script.rhai").unwrap());
|
|
|
|
//! # let _ = remove_file("my_script.rhai");
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! [Check out the README on github for more information!](https://github.com/jonathandturner/rhai)
|
2016-03-03 16:55:28 +01:00
|
|
|
|
2017-10-02 23:44:45 +02:00
|
|
|
// lints required by Rhai
|
|
|
|
#![allow(unknown_lints,
|
|
|
|
type_complexity,
|
|
|
|
new_without_default_derive,
|
|
|
|
needless_pass_by_value,
|
|
|
|
too_many_arguments)]
|
|
|
|
|
2016-03-03 16:55:28 +01:00
|
|
|
mod engine;
|
|
|
|
mod fn_register;
|
|
|
|
mod parser;
|
|
|
|
|
2017-10-14 19:46:40 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2016-03-04 14:45:43 +01:00
|
|
|
pub use engine::{Engine, Scope};
|
2016-03-03 16:55:28 +01:00
|
|
|
pub use fn_register::FnRegister;
|
2017-10-28 22:33:00 +02:00
|
|
|
|