Macro rhai::def_package [−][src]
macro_rules! def_package { ($root:ident : $package:ident : $comment:expr , $lib:ident , $block:stmt) => { ... }; }
Expand description
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 Module::set_native_fn
.
Example
Define a package named MyPackage
with a single function named my_add
:
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_native_fn("my_add", add); });