Crate quad_compat_rhai

Source
Expand description

§Rhai - embedded scripting for Rust

Rhai logo

Rhai is a tiny, simple and 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 JavaScript+Rust and a simple Rust interface.

§A Quick Example

§Contents of my_script.rhai

/// Brute force factorial function
fn factorial(x) {
    if x == 1 { return 1; }
    x * factorial(x - 1)
}

// Calling an external function 'compute'
compute(factorial(10))

§The Rust part

use quad_compat_rhai::{Engine, EvalAltResult};

fn main() -> Result<(), Box<EvalAltResult>>
{
    // Define external function
    fn compute_something(x: i64) -> bool {
        (x % 40) == 0
    }

    // Create scripting engine
    let mut engine = Engine::new();

    // Register external function as 'compute'
    engine.register_fn("compute", compute_something);

    assert_eq!(
        // Evaluate the script, expects a 'bool' return
        engine.eval_file::<bool>("my_script.rhai".into())?,
        true
    );

    Ok(())
}

§Documentation

See The Rhai Book for details on the Rhai scripting engine and language.

Modules§

  • Module containing all built-in module resolvers available to Rhai. Module containing all built-in module resolvers.
  • Module containing all built-in packages available to Rhai, plus facilities to define custom packages.
  • Module defining macros for developing plugins.
  • (serde) Serialization and deserialization support for serde. Exported under the serde feature only.

Macros§

Structs§

  • Compiled AST (abstract syntax tree) of a Rhai script.
  • (internals) A binary expression. Exported under the internals feature only.
  • (internals) A custom syntax expression. Exported under the internals feature only.
  • Dynamic type containing any value.
  • (internals) Lock guard for reading a Dynamic. Exported under the internals feature only.
  • (internals) Lock guard for writing a Dynamic. Exported under the internals feature only.
  • Rhai main scripting engine.
  • Context of a script evaluation process.
  • (internals) A type that holds all the current states of the Engine. Exported under the internals feature only.
  • An expression sub-tree in an AST.
  • A type that wraps a floating-point number and implements Hash.
  • (internals) A function call. Exported under the internals feature only.
  • (internals) A set of function call hashes. Exported under the internals feature only.
  • A general function pointer, which may carry additional (i.e. curried) argument values to be passed onto a function during a call.
  • (internals) An entry in a function resolution cache. Exported under the internals feature only.
  • (internals) An identifier containing a name and a position. Exported under the internals feature only.
  • (internals) A factory of identifiers from text strings. Exported under the internals feature only.
  • The system immutable string type.
  • (internals) A stack of imported modules plus mutable runtime global states. Exported under the internals feature only.
  • Alias to RefCell or RwLock depending on the sync feature flag. Synchronized shared object. A mutable memory location with dynamically checked borrow rules
  • A module which may contain variables, sub-modules, external Rust functions, and/or script-defined functions.
  • (internals) A type that implements the InputStream trait. Exported under the internals feature only.
  • (internals) A chain of module names to namespace-qualify a variable or function call. Exported under the internals feature only.
  • Context of a native Rust function call.
  • (internals) An op-assignment operator. Exported under the internals feature only.
  • A type that holds a configuration option with bit-flags. Exported under the internals feature only.
  • Error when parsing a script.
  • (internals) A type that encapsulates the current state of the parser. Exported under the internals feature only.
  • A location (line number + character position) in the input script.
  • Type containing information about the current scope. Useful for keeping state between Engine evaluation runs.
  • (internals) A type containing information on a scripted function. Exported under the internals feature only.
  • A type containing the metadata of a script-defined function.
  • Alias to Rc or Arc depending on the sync feature flag. Immutable reference-counted container. A single-threaded reference-counting pointer. ‘Rc’ stands for ‘Reference Counted’.
  • (internals) A scoped block of statements. Exported under the internals feature only.
  • (internals) An iterator on a Token stream. Exported under the internals feature only.
  • (internals) State of the tokenizer. Exported under the internals feature only.
  • (internals) A type containing commands to control the tokenizer.

Enums§

  • (internals) An AST node, consisting of either an Expr or a Stmt. Exported under the internals feature only.
  • (internals) Modes of access. Exported under the internals feature only.
  • Evaluation result.
  • (internals) An expression sub-tree. Exported under the internals feature only.
  • A type representing the access mode of a function.
  • A type representing the namespace of a function.
  • (internals) Error encountered when tokenizing the script text. Exported under the internals feature only.
  • Level of optimization performed.
  • Type of error encountered when parsing a script.
  • (internals) A statement. Exported under the internals feature only.
  • (internals) A Rhai language token. Exported under the internals feature only.

Constants§

Traits§

  • Trait to create a Rust closure from a script.
  • Trait that parses arguments to a function call.
  • (internals) Trait that encapsulates a peekable character input stream. Exported under the internals feature only.
  • Trait that encapsulates a module resolution service.
  • Trait to register custom Rust functions.
  • (internals) Trait to represent any type. Exported under the internals feature only.

Functions§

  • (internals) Get the next token from the stream. Exported under the internals feature only.
  • (internals) Parse a string literal ended by termination_char. Exported under the internals feature only.

Type Aliases§

  • Variable-sized array of Dynamic values. Not available under no_index.
  • Variable-sized array of u8 values (byte array). Not available under no_index.
  • The system floating-point type. It is defined as f64. Not available under no_float.
  • (internals) A function resolution cache. Exported under the internals feature only.
  • The system integer type. It is defined as i64.
  • An identifier in Rhai. SmartString is used because most identifiers are ASCII and short, fewer than 23 characters, so they can be stored inline.
  • Hash map of Dynamic values with SmartString keys. Not available under no_object.
  • (internals) Alias to smallvec::SmallVec<[T; 3]>, which is a Vec backed by a small, inline, fixed-size array when there are ≤ 3 items stored. Exported under the internals feature only.
  • (internals) A shared object that allows control of the tokenizer from outside.

Attribute Macros§

  • Attribute, when put on a Rust function, turns it into a plugin function.
  • Attribute, when put on a Rust module, turns it into a plugin module.