Use modules to implement packages.

This commit is contained in:
Stephen Chung
2020-05-13 19:21:42 +08:00
parent d613764c03
commit 30e5e2f034
18 changed files with 610 additions and 1023 deletions

View File

@@ -125,9 +125,8 @@ impl Engine {
/// Register an iterator adapter for a type with the `Engine`.
/// This is an advanced feature.
pub fn register_iterator<T: Variant + Clone, F: IteratorCallback>(&mut self, f: F) {
self.base_package
.type_iterators
.insert(TypeId::of::<T>(), Box::new(f));
self.global_module
.set_iterator(TypeId::of::<T>(), Box::new(f));
}
/// Register a getter function for a member of a registered type with the `Engine`.
@@ -419,7 +418,7 @@ impl Engine {
/// // into function calls and operators.
/// let ast = engine.compile_scripts_with_scope(&mut scope, &[
/// "if x > 40", // all 'x' are replaced with 42
/// "{ x } el"
/// "{ x } el",
/// "se { 0 }" // segments do not need to be valid scripts!
/// ])?;
///