Consistent naming of methods.
This commit is contained in:
parent
5a02548ebc
commit
9d8d074940
@ -125,8 +125,7 @@ impl Engine {
|
|||||||
/// Register an iterator adapter for a type with the `Engine`.
|
/// Register an iterator adapter for a type with the `Engine`.
|
||||||
/// This is an advanced feature.
|
/// This is an advanced feature.
|
||||||
pub fn register_iterator<T: Variant + Clone, F: IteratorCallback>(&mut self, f: F) {
|
pub fn register_iterator<T: Variant + Clone, F: IteratorCallback>(&mut self, f: F) {
|
||||||
self.global_module
|
self.global_module.set_iter(TypeId::of::<T>(), Box::new(f));
|
||||||
.set_iterator(TypeId::of::<T>(), Box::new(f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a getter function for a member of a registered type with the `Engine`.
|
/// Register a getter function for a member of a registered type with the `Engine`.
|
||||||
|
@ -552,7 +552,7 @@ impl Engine {
|
|||||||
if let Some(func) = self
|
if let Some(func) = self
|
||||||
.global_module
|
.global_module
|
||||||
.get_fn(hashes.0)
|
.get_fn(hashes.0)
|
||||||
.or_else(|| self.packages.get_function(hashes.0))
|
.or_else(|| self.packages.get_fn(hashes.0))
|
||||||
{
|
{
|
||||||
let mut backup: Dynamic = Default::default();
|
let mut backup: Dynamic = Default::default();
|
||||||
|
|
||||||
@ -728,7 +728,7 @@ impl Engine {
|
|||||||
// First check registered functions
|
// First check registered functions
|
||||||
self.global_module.contains_fn(hashes.0)
|
self.global_module.contains_fn(hashes.0)
|
||||||
// Then check packages
|
// Then check packages
|
||||||
|| self.packages.contains_function(hashes.0)
|
|| self.packages.contains_fn(hashes.0)
|
||||||
// Then check script-defined functions
|
// Then check script-defined functions
|
||||||
|| state.has_function(hashes.1)
|
|| state.has_function(hashes.1)
|
||||||
}
|
}
|
||||||
@ -1573,8 +1573,8 @@ impl Engine {
|
|||||||
|
|
||||||
if let Some(iter_fn) = self
|
if let Some(iter_fn) = self
|
||||||
.global_module
|
.global_module
|
||||||
.get_iterator(tid)
|
.get_iter(tid)
|
||||||
.or_else(|| self.packages.get_iterator(tid))
|
.or_else(|| self.packages.get_iter(tid))
|
||||||
{
|
{
|
||||||
// Add the loop variable
|
// Add the loop variable
|
||||||
let name = x.0.clone();
|
let name = x.0.clone();
|
||||||
|
@ -92,7 +92,6 @@ macro_rules! def_anonymous_fn {
|
|||||||
{
|
{
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
type Output = Box<dyn Fn($($par),*) -> Result<RET, Box<EvalAltResult>> + Send + Sync>;
|
type Output = Box<dyn Fn($($par),*) -> Result<RET, Box<EvalAltResult>> + Send + Sync>;
|
||||||
|
|
||||||
#[cfg(not(feature = "sync"))]
|
#[cfg(not(feature = "sync"))]
|
||||||
type Output = Box<dyn Fn($($par),*) -> Result<RET, Box<EvalAltResult>>>;
|
type Output = Box<dyn Fn($($par),*) -> Result<RET, Box<EvalAltResult>>>;
|
||||||
|
|
||||||
|
@ -567,20 +567,6 @@ impl Module {
|
|||||||
.ok_or_else(|| Box::new(EvalAltResult::ErrorFunctionNotFound(name.to_string(), pos)))
|
.ok_or_else(|| Box::new(EvalAltResult::ErrorFunctionNotFound(name.to_string(), pos)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the script-defined functions.
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// use rhai::Module;
|
|
||||||
///
|
|
||||||
/// let mut module = Module::new();
|
|
||||||
/// assert_eq!(module.get_fn_lib().len(), 0);
|
|
||||||
/// ```
|
|
||||||
pub fn get_fn_lib(&self) -> &FunctionsLib {
|
|
||||||
&self.fn_lib
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a modules-qualified script-defined functions.
|
/// Get a modules-qualified script-defined functions.
|
||||||
///
|
///
|
||||||
/// The `u64` hash is calculated by the function `crate::calc_fn_hash`.
|
/// The `u64` hash is calculated by the function `crate::calc_fn_hash`.
|
||||||
@ -720,12 +706,12 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Does a type iterator exist in the module?
|
/// Does a type iterator exist in the module?
|
||||||
pub fn contains_iterator(&self, id: TypeId) -> bool {
|
pub fn contains_iter(&self, id: TypeId) -> bool {
|
||||||
self.type_iterators.contains_key(&id)
|
self.type_iterators.contains_key(&id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a type iterator into the module.
|
/// Set a type iterator into the module.
|
||||||
pub fn set_iterator(&mut self, typ: TypeId, func: Box<IteratorFn>) {
|
pub fn set_iter(&mut self, typ: TypeId, func: Box<IteratorFn>) {
|
||||||
#[cfg(not(feature = "sync"))]
|
#[cfg(not(feature = "sync"))]
|
||||||
self.type_iterators.insert(typ, Rc::new(func));
|
self.type_iterators.insert(typ, Rc::new(func));
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
@ -733,7 +719,7 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the specified type iterator.
|
/// Get the specified type iterator.
|
||||||
pub fn get_iterator(&self, id: TypeId) -> Option<&SharedIteratorFunction> {
|
pub fn get_iter(&self, id: TypeId) -> Option<&SharedIteratorFunction> {
|
||||||
self.type_iterators.get(&id)
|
self.type_iterators.get(&id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ fn call_fn(
|
|||||||
|
|
||||||
global_module
|
global_module
|
||||||
.get_fn(hash)
|
.get_fn(hash)
|
||||||
.or_else(|| packages.get_function(hash))
|
.or_else(|| packages.get_fn(hash))
|
||||||
.map(|func| func.call(args, pos))
|
.map(|func| func.call(args, pos))
|
||||||
.transpose()
|
.transpose()
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Register array iterator
|
// Register array iterator
|
||||||
lib.set_iterator(
|
lib.set_iter(
|
||||||
TypeId::of::<Array>(),
|
TypeId::of::<Array>(),
|
||||||
Box::new(|arr| Box::new(
|
Box::new(|arr| Box::new(
|
||||||
arr.cast::<Array>().into_iter()) as Box<dyn Iterator<Item = Dynamic>>
|
arr.cast::<Array>().into_iter()) as Box<dyn Iterator<Item = Dynamic>>
|
||||||
|
@ -14,7 +14,7 @@ fn reg_range<T: Variant + Clone>(lib: &mut Module)
|
|||||||
where
|
where
|
||||||
Range<T>: Iterator<Item = T>,
|
Range<T>: Iterator<Item = T>,
|
||||||
{
|
{
|
||||||
lib.set_iterator(
|
lib.set_iter(
|
||||||
TypeId::of::<Range<T>>(),
|
TypeId::of::<Range<T>>(),
|
||||||
Box::new(|source| {
|
Box::new(|source| {
|
||||||
Box::new(source.cast::<Range<T>>().map(|x| x.into_dynamic()))
|
Box::new(source.cast::<Range<T>>().map(|x| x.into_dynamic()))
|
||||||
@ -58,7 +58,7 @@ where
|
|||||||
T: Variant + Clone + PartialOrd,
|
T: Variant + Clone + PartialOrd,
|
||||||
StepRange<T>: Iterator<Item = T>,
|
StepRange<T>: Iterator<Item = T>,
|
||||||
{
|
{
|
||||||
lib.set_iterator(
|
lib.set_iter(
|
||||||
TypeId::of::<StepRange<T>>(),
|
TypeId::of::<StepRange<T>>(),
|
||||||
Box::new(|source| {
|
Box::new(|source| {
|
||||||
Box::new(source.cast::<StepRange<T>>().map(|x| x.into_dynamic()))
|
Box::new(source.cast::<StepRange<T>>().map(|x| x.into_dynamic()))
|
||||||
|
@ -64,11 +64,11 @@ impl PackagesCollection {
|
|||||||
self.packages.insert(0, package);
|
self.packages.insert(0, package);
|
||||||
}
|
}
|
||||||
/// Does the specified function hash key exist in the `PackagesCollection`?
|
/// Does the specified function hash key exist in the `PackagesCollection`?
|
||||||
pub fn contains_function(&self, hash: u64) -> bool {
|
pub fn contains_fn(&self, hash: u64) -> bool {
|
||||||
self.packages.iter().any(|p| p.contains_fn(hash))
|
self.packages.iter().any(|p| p.contains_fn(hash))
|
||||||
}
|
}
|
||||||
/// Get specified function via its hash key.
|
/// Get specified function via its hash key.
|
||||||
pub fn get_function(&self, hash: u64) -> Option<&Box<dyn NativeCallable>> {
|
pub fn get_fn(&self, hash: u64) -> Option<&Box<dyn NativeCallable>> {
|
||||||
self.packages
|
self.packages
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| p.get_fn(hash))
|
.map(|p| p.get_fn(hash))
|
||||||
@ -76,14 +76,14 @@ impl PackagesCollection {
|
|||||||
.flatten()
|
.flatten()
|
||||||
}
|
}
|
||||||
/// Does the specified TypeId iterator exist in the `PackagesCollection`?
|
/// Does the specified TypeId iterator exist in the `PackagesCollection`?
|
||||||
pub fn contains_iterator(&self, id: TypeId) -> bool {
|
pub fn contains_iter(&self, id: TypeId) -> bool {
|
||||||
self.packages.iter().any(|p| p.contains_iterator(id))
|
self.packages.iter().any(|p| p.contains_iter(id))
|
||||||
}
|
}
|
||||||
/// Get the specified TypeId iterator.
|
/// Get the specified TypeId iterator.
|
||||||
pub fn get_iterator(&self, id: TypeId) -> Option<&SharedIteratorFunction> {
|
pub fn get_iter(&self, id: TypeId) -> Option<&SharedIteratorFunction> {
|
||||||
self.packages
|
self.packages
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| p.get_iterator(id))
|
.map(|p| p.get_iter(id))
|
||||||
.find(|f| f.is_some())
|
.find(|f| f.is_some())
|
||||||
.flatten()
|
.flatten()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user