diff --git a/src/engine.rs b/src/engine.rs index 0fa2ee9f..44cd129a 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -125,15 +125,23 @@ impl Imports { /// Does the specified function hash key exist in this stack of imported [modules][Module]? #[allow(dead_code)] pub fn contains_fn(&self, hash: u64) -> bool { - self.0.as_ref().map_or(false, |x| { - x.iter().any(|(_, m)| m.contains_qualified_fn(hash)) - }) + if hash == 0 { + false + } else { + self.0.as_ref().map_or(false, |x| { + x.iter().any(|(_, m)| m.contains_qualified_fn(hash)) + }) + } } /// Get specified function via its hash key. pub fn get_fn(&self, hash: u64) -> Option<&CallableFunction> { - self.0 - .as_ref() - .and_then(|x| x.iter().rev().find_map(|(_, m)| m.get_qualified_fn(hash))) + if hash == 0 { + None + } else { + self.0 + .as_ref() + .and_then(|x| x.iter().rev().find_map(|(_, m)| m.get_qualified_fn(hash))) + } } /// Does the specified [`TypeId`][std::any::TypeId] iterator exist in this stack of imported [modules][Module]? #[allow(dead_code)] diff --git a/src/fn_call.rs b/src/fn_call.rs index 82673b20..bb8720cb 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -443,8 +443,8 @@ impl Engine { // NOTE: We skip script functions for global_namespace and packages, and native functions for lib // First check script-defined functions - lib.iter().any(|&m| m.contains_fn(hash_script, pub_only)) - //|| lib.iter().any(|&m| m.contains_fn(hash_fn, pub_only)) + (hash_script != 0 && lib.iter().any(|&m| m.contains_fn(hash_script, pub_only))) + //|| (hash_fn != 0 && lib.iter().any(|&m| m.contains_fn(hash_fn, pub_only))) // Then check registered functions //|| self.global_namespace.contains_fn(hash_script, pub_only) || self.global_namespace.contains_fn(hash_fn, false) diff --git a/src/packages/mod.rs b/src/packages/mod.rs index bc764554..ca42cced 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -64,15 +64,23 @@ impl PackagesCollection { /// Does the specified function hash key exist in the [`PackagesCollection`]? #[allow(dead_code)] pub fn contains_fn(&self, hash: u64) -> bool { - self.0 - .as_ref() - .map_or(false, |x| x.iter().any(|p| p.contains_fn(hash, false))) + if hash == 0 { + false + } else { + self.0 + .as_ref() + .map_or(false, |x| x.iter().any(|p| p.contains_fn(hash, false))) + } } /// Get specified function via its hash key. pub fn get_fn(&self, hash: u64) -> Option<&CallableFunction> { - self.0 - .as_ref() - .and_then(|x| x.iter().find_map(|p| p.get_fn(hash, false))) + if hash == 0 { + None + } else { + self.0 + .as_ref() + .and_then(|x| x.iter().find_map(|p| p.get_fn(hash, false))) + } } /// Does the specified [`TypeId`] iterator exist in the [`PackagesCollection`]? #[allow(dead_code)] diff --git a/src/parser.rs b/src/parser.rs index f0003abd..946f9653 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -357,6 +357,7 @@ fn parse_fn_call( return Ok(Expr::FnCall( Box::new(FnCallExpr { name: id.to_string().into(), + native_only: !is_valid_identifier(id.chars()), // script functions can only be valid identifiers capture, namespace, hash: hash_script, @@ -404,6 +405,7 @@ fn parse_fn_call( return Ok(Expr::FnCall( Box::new(FnCallExpr { name: id.to_string().into(), + native_only: !is_valid_identifier(id.chars()), // script functions can only be valid identifiers capture, namespace, hash: hash_script,