fix(defs): compile errors

This commit is contained in:
tamasfe 2022-07-26 14:28:54 +02:00
parent d350462cf8
commit ade818b043
No known key found for this signature in database
GPG Key ID: 2373047D27CA4E47
2 changed files with 24 additions and 17 deletions

View File

@ -18,11 +18,15 @@ fn main() {
// since it will be part of the scope. // since it will be part of the scope.
scope.push("hello_there", "hello there"); scope.push("hello_there", "hello there");
#[cfg(not(feature = "no_module"))]
engine.register_static_module("general_kenobi", exported_module!(general_kenobi).into()); engine.register_static_module("general_kenobi", exported_module!(general_kenobi).into());
// Custom operators also show up in definitions. // Custom operators also show up in definitions.
engine.register_custom_operator("minus", 100).unwrap(); #[cfg(not(feature = "no_custom_syntax"))]
engine.register_fn("minus", |a: i64, b: i64| a - b); {
engine.register_custom_operator("minus", 100).unwrap();
engine.register_fn("minus", |a: i64, b: i64| a - b);
}
engine engine
.eval_with_scope::<()>( .eval_with_scope::<()>(

View File

@ -169,29 +169,32 @@ impl<'e> Definitions<'e> {
s s
} }
/// Return name and definition pairs for each registered module. /// Return module name and definition pairs for each registered module.
/// ///
/// The definitions will always start with `module <module name>;`. /// The definitions will always start with `module <module name>;`.
/// ///
/// If the feature `no_module` is enabled, this will yield no elements. /// If the feature `no_module` is enabled, this will yield no elements.
pub fn modules(&self) -> impl Iterator<Item = (String, String)> + '_ { pub fn modules(&self) -> impl Iterator<Item = (String, String)> + '_ {
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
let mut m = self let m = {
.engine let mut m = self
.global_sub_modules .engine
.iter() .global_sub_modules
.map(move |(name, module)| { .iter()
( .map(move |(name, module)| {
name.to_string(), (
format!("module {name};\n\n{}", module.definition(self)), name.to_string(),
) format!("module {name};\n\n{}", module.definition(self)),
}) )
.collect::<Vec<_>>(); })
.collect::<Vec<_>>();
m.sort_by(|(name1, _), (name2, _)| name1.cmp(name2));
m
};
#[cfg(feature = "no_module")] #[cfg(feature = "no_module")]
let mut m = Vec::new(); let m = Vec::new();
m.sort_by(|(name1, _), (name2, _)| name1.cmp(name2));
m.into_iter() m.into_iter()
} }