Raw Engine

Engine::new creates a scripting Engine with common functionalities (e.g. printing to stdout via print or debug).

In many controlled embedded environments, however, these may not be needed and unnecessarily occupy application code storage space.

Built-in operators

Even with a raw Engine, some operators are built-in and always available.

See Built-in Operators for a full list.

Use Engine::new_raw to create a raw Engine, in which only a minimal set of built-in basic arithmetic and logical operators are supported.

To add more functionalities to a raw Engine, load packages into it.

Since packages can be shared, this is an extremely efficient way to create multiple instances of the same Engine with the same set of functions.

Built-in operatorsyesyes
Package loadedStandardPackagenone
Module resolverFileModuleResolvernone

Engine::new is equivalent to…

use rhai::module_resolvers::FileModuleResolver;
use rhai::packages::StandardPackage;

// Create a raw scripting Engine
let mut engine = Engine::new_raw();

// Use the file-based module resolver

// Default print/debug implementations
engine.on_print(|text| println!("{text}"));

engine.on_debug(|text, source, pos| match (source, pos) {
    (Some(source), crate::Position::NONE) => println!("{source} | {text}"),
    (Some(source), pos) => println!("{source} @ {pos:?} | {text}"),
    (None, crate::Position::NONE) => println!("{text}"),
    (None, pos) => println!("{pos:?} | {text}"),

// Register the Standard Package
let package = StandardPackage::new();

// Load the package into the [`Engine`]
package.register_into_engine(&mut engine);