diff --git a/RELEASES.md b/RELEASES.md index 8a4cd93b..cb37b9d8 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -10,7 +10,7 @@ Breaking changes * `EvalAltResult::ErrorReadingScriptFile` is removed in favor of the new `EvalAltResult::ErrorSystem`. * `EvalAltResult::ErrorLoopBreak` is renamed to `EvalAltResult::LoopBreak`. -* `Engine::register_raw_fn` function signature has changed. +* `Engine::register_raw_fn` and `FnPtr::call_dynamic` function signatures have changed. New features ------------ diff --git a/src/engine.rs b/src/engine.rs index 46af0581..bc7063dc 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -425,7 +425,7 @@ pub struct Limits { pub max_operations: u64, /// Maximum number of modules allowed to load. /// Not available under `no_module`. - #[cfg(not(feature = "no_modules"))] + #[cfg(not(feature = "no_module"))] pub max_modules: usize, /// Maximum length of a string (0 = unlimited). pub max_string_size: usize, @@ -459,7 +459,7 @@ impl<'e, 'a, 's, 'm, 't, 'd> EvalContext<'e, 'a, 's, 'm, 't, 'd> { /// _[INTERNALS]_ The current set of modules imported via `import` statements. /// Available under the `internals` feature only. #[cfg(feature = "internals")] - #[cfg(not(feature = "no_modules"))] + #[cfg(not(feature = "no_module"))] #[inline(always)] pub fn imports(&self) -> &'a Imports { self.mods diff --git a/src/module/mod.rs b/src/module/mod.rs index 66c08875..53fd915f 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -1586,6 +1586,7 @@ impl ModuleRef { pub(crate) fn index(&self) -> Option { self.1 } + #[cfg(not(feature = "no_module"))] pub(crate) fn set_index(&mut self, index: Option) { self.1 = index } diff --git a/src/packages/fn_basic.rs b/src/packages/fn_basic.rs index 6816407d..64494290 100644 --- a/src/packages/fn_basic.rs +++ b/src/packages/fn_basic.rs @@ -12,8 +12,12 @@ mod fn_ptr_functions { pub fn name(f: &mut FnPtr) -> ImmutableString { f.get_fn_name().clone() } - #[rhai_fn(name = "is_anonymous", get = "is_anonymous")] - pub fn is_anonymous(f: &mut FnPtr) -> bool { - f.is_anonymous() + + #[cfg(not(feature = "no_function"))] + pub mod anonymous { + #[rhai_fn(name = "is_anonymous", get = "is_anonymous")] + pub fn is_anonymous(f: &mut FnPtr) -> bool { + f.is_anonymous() + } } } diff --git a/src/parser.rs b/src/parser.rs index b957ebeb..8cedfae7 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -679,19 +679,15 @@ impl<'e> ParseState<'e> { /// # Panics /// /// Panics when called under `no_module`. + #[cfg(not(feature = "no_module"))] #[inline(always)] pub fn find_module(&self, name: &str) -> Option { - #[cfg(feature = "no_module")] - unreachable!(); - - #[cfg(not(feature = "no_module"))] - return self - .modules + self.modules .iter() .rev() .enumerate() .find(|(_, n)| *n == name) - .and_then(|(i, _)| NonZeroUsize::new(i + 1)); + .and_then(|(i, _)| NonZeroUsize::new(i + 1)) } } @@ -1422,6 +1418,7 @@ fn parse_fn_call( eat_token(input, Token::RightParen); let hash_script = if let Some(modules) = modules.as_mut() { + #[cfg(not(feature = "no_module"))] modules.set_index(state.find_module(&modules[0].0)); // Rust functions are indexed in two steps: @@ -1464,6 +1461,7 @@ fn parse_fn_call( eat_token(input, Token::RightParen); let hash_script = if let Some(modules) = modules.as_mut() { + #[cfg(not(feature = "no_module"))] modules.set_index(state.find_module(&modules[0].0)); // Rust functions are indexed in two steps: @@ -2049,6 +2047,8 @@ fn parse_primary( // Qualifiers + variable name *hash = calc_fn_hash(modules.iter().map(|(v, _)| v.as_str()), name, 0, empty()); + + #[cfg(not(feature = "no_module"))] modules.set_index(state.find_module(&modules[0].0)); } _ => (), @@ -3092,6 +3092,8 @@ fn parse_block( let mut statements = StaticVec::new(); let prev_stack_len = state.stack.len(); + + #[cfg(not(feature = "no_module"))] let prev_mods_len = state.modules.len(); while !match_token(input, Token::RightBrace)? { @@ -3137,6 +3139,8 @@ fn parse_block( } state.stack.truncate(prev_stack_len); + + #[cfg(not(feature = "no_module"))] state.modules.truncate(prev_mods_len); Ok(Stmt::Block(Box::new((statements, settings.pos)))) diff --git a/src/settings.rs b/src/settings.rs index c72fe2d8..bd23114a 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -86,6 +86,7 @@ impl Engine { /// Set the maximum number of imported modules allowed for a script. #[cfg(not(feature = "unchecked"))] + #[cfg(not(feature = "no_module"))] #[inline(always)] pub fn set_max_modules(&mut self, modules: usize) -> &mut Self { self.limits_set.max_modules = modules; @@ -94,6 +95,7 @@ impl Engine { /// The maximum number of imported modules allowed for a script. #[cfg(not(feature = "unchecked"))] + #[cfg(not(feature = "no_module"))] #[inline(always)] pub fn max_modules(&self) -> usize { self.limits_set.max_modules