Add combine_with_exported_module.

This commit is contained in:
Stephen Chung
2020-09-13 22:12:11 +08:00
committed by J Henry Waugh
parent aed70db303
commit 848bdf3f01
16 changed files with 64 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
#![cfg(not(any(feature = "no_index", feature = "no_module")))]
use rhai::module_resolvers::StaticModuleResolver;
use rhai::plugin::*;
use rhai::{Engine, EvalAltResult, INT};
@@ -10,6 +11,8 @@ mod test {
pub mod special_array_package {
use rhai::{Array, INT};
pub const MYSTIC_NUMBER: INT = 42 as INT;
#[cfg(not(feature = "no_object"))]
pub mod feature {
use rhai::{Array, Dynamic, EvalAltResult};
@@ -66,7 +69,7 @@ fn test_plugins_package() -> Result<(), Box<EvalAltResult>> {
let mut engine = Engine::new();
let mut m = Module::new();
m.combine_flatten(exported_module!(test::special_array_package));
combine_with_exported_module!(&mut m, "test", test::special_array_package);
engine.load_package(m);
reg_functions!(engine += greet::single(INT, bool, char));
@@ -83,5 +86,14 @@ fn test_plugins_package() -> Result<(), Box<EvalAltResult>> {
"6 kitties"
);
let mut resolver = StaticModuleResolver::new();
resolver.insert("test", exported_module!(test::special_array_package));
engine.set_module_resolver(Some(resolver));
assert_eq!(
engine.eval::<INT>(r#"import "test" as test; test::MYSTIC_NUMBER"#)?,
42
);
Ok(())
}