Fix no_function and no_module builds.
This commit is contained in:
parent
232ff91957
commit
dc4c47e008
@ -1,7 +1,7 @@
|
|||||||
//! Module defining interfaces to native-Rust functions.
|
//! Module defining interfaces to native-Rust functions.
|
||||||
|
|
||||||
use crate::any::Dynamic;
|
use crate::any::Dynamic;
|
||||||
use crate::engine::{Engine, EvalContext, FN_ANONYMOUS};
|
use crate::engine::{Engine, EvalContext};
|
||||||
use crate::module::Module;
|
use crate::module::Module;
|
||||||
use crate::parser::{FnAccess, ScriptFnDef};
|
use crate::parser::{FnAccess, ScriptFnDef};
|
||||||
use crate::plugin::PluginFunction;
|
use crate::plugin::PluginFunction;
|
||||||
@ -11,6 +11,9 @@ use crate::token::{is_valid_identifier, Position};
|
|||||||
use crate::utils::ImmutableString;
|
use crate::utils::ImmutableString;
|
||||||
use crate::{calc_fn_hash, StaticVec};
|
use crate::{calc_fn_hash, StaticVec};
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_function"))]
|
||||||
|
use crate::engine::FN_ANONYMOUS;
|
||||||
|
|
||||||
use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, iter::empty, mem, string::String};
|
use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, iter::empty, mem, string::String};
|
||||||
|
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
@ -138,6 +141,7 @@ impl FnPtr {
|
|||||||
self.1.as_ref()
|
self.1.as_ref()
|
||||||
}
|
}
|
||||||
/// Does this function pointer refer to an anonymous function?
|
/// Does this function pointer refer to an anonymous function?
|
||||||
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_anonymous(&self) -> bool {
|
pub fn is_anonymous(&self) -> bool {
|
||||||
self.0.starts_with(FN_ANONYMOUS)
|
self.0.starts_with(FN_ANONYMOUS)
|
||||||
|
@ -670,17 +670,28 @@ impl<'e> ParseState<'e> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Find a module by name in the `ParseState`, searching in reverse.
|
/// Find a module by name in the `ParseState`, searching in reverse.
|
||||||
/// The return value is the offset to be deducted from `Stack::len`,
|
///
|
||||||
|
/// Returns the offset to be deducted from `Stack::len`,
|
||||||
/// i.e. the top element of the `ParseState` is offset 1.
|
/// i.e. the top element of the `ParseState` is offset 1.
|
||||||
/// Return `None` when the variable name is not found in the `ParseState`.
|
///
|
||||||
|
/// Returns `None` when the variable name is not found in the `ParseState`.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics when called under `no_module`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn find_module(&self, name: &str) -> Option<NonZeroUsize> {
|
pub fn find_module(&self, name: &str) -> Option<NonZeroUsize> {
|
||||||
self.modules
|
#[cfg(feature = "no_module")]
|
||||||
|
unreachable!();
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_module"))]
|
||||||
|
return self
|
||||||
|
.modules
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.find(|(_, n)| *n == name)
|
.find(|(_, n)| *n == name)
|
||||||
.and_then(|(i, _)| NonZeroUsize::new(i + 1))
|
.and_then(|(i, _)| NonZeroUsize::new(i + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user