Attribute Macro rhai_codegen::export_module

source ·
#[export_module]
Expand description

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

§Usage

use rhai::plugin::*;

#[export_module]
mod my_plugin_module {
    pub fn foo(x: i64) -> i64 { x * 2 }
    pub fn bar() -> i64 { 21 }
}

let mut engine = Engine::new();

let module = exported_module!(my_plugin_module);

engine.register_global_module(module.into());

assert_eq!(engine.eval::<i64>("foo(bar())")?, 42);