[][src]Macro rhai::def_package

macro_rules! def_package {
    ($root:ident : $package:ident : $comment:expr , $lib:ident , $block:stmt) => { ... };
}

Macro that makes it easy to define a package (which is basically a shared module) and register functions into it.

Functions can be added to the package using the standard module methods such as set_fn_2, set_fn_3_mut, set_fn_0 etc.

Examples

use rhai::{Dynamic, EvalAltResult};
use rhai::def_package;

fn add(x: i64, y: i64) -> Result<i64, Box<EvalAltResult>> { Ok(x + y) }

def_package!(rhai:MyPackage:"My super-duper package", lib,
{
    // Load a binary function with all value parameters.
    lib.set_fn_2("my_add", add);
});

The above defines a package named 'MyPackage' with a single function named 'my_add'.