Native only if function call is not a valid identifier.

This commit is contained in:
Stephen Chung 2020-12-18 23:03:56 +08:00
parent 5454ff0cd5
commit db7b9cb0f9
4 changed files with 32 additions and 14 deletions

View File

@ -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)]

View File

@ -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)

View File

@ -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)]

View File

@ -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,