Macro quad_compat_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 quad_compat_rhai::{Dynamic, EvalAltResult};
use quad_compat_rhai::def_package;
fn add(x: i64, y: i64) -> Result<i64, Box<EvalAltResult>> { Ok(x + y) }
def_package!(rhai:MyPackage:"My super-duper package", module,
{
// Load a binary function with all value parameters.
module.set_native_fn("my_add", add);
});