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.
scope.push("hello_there", "hello there");
#[cfg(not(feature = "no_module"))]
engine.register_static_module("general_kenobi", exported_module!(general_kenobi).into());
// Custom operators also show up in definitions.
engine.register_custom_operator("minus", 100).unwrap();
engine.register_fn("minus", |a: i64, b: i64| a - b);
#[cfg(not(feature = "no_custom_syntax"))]
{
engine.register_custom_operator("minus", 100).unwrap();
engine.register_fn("minus", |a: i64, b: i64| a - b);
}
engine
.eval_with_scope::<()>(

View File

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