global_module -> global_namespace.
This commit is contained in:
parent
a00d6ba99e
commit
5e4ede6f07
@ -599,7 +599,7 @@ pub struct Engine {
|
|||||||
pub id: String,
|
pub id: String,
|
||||||
|
|
||||||
/// A module containing all functions directly loaded into the Engine.
|
/// A module containing all functions directly loaded into the Engine.
|
||||||
pub(crate) global_module: Module,
|
pub(crate) global_namespace: Module,
|
||||||
/// A collection of all library packages loaded into the Engine.
|
/// A collection of all library packages loaded into the Engine.
|
||||||
pub(crate) packages: PackagesCollection,
|
pub(crate) packages: PackagesCollection,
|
||||||
/// A collection of all sub-modules directly loaded into the Engine.
|
/// A collection of all sub-modules directly loaded into the Engine.
|
||||||
@ -718,7 +718,7 @@ impl Engine {
|
|||||||
id: Default::default(),
|
id: Default::default(),
|
||||||
|
|
||||||
packages: Default::default(),
|
packages: Default::default(),
|
||||||
global_module: Default::default(),
|
global_namespace: Default::default(),
|
||||||
global_sub_modules: Default::default(),
|
global_sub_modules: Default::default(),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
@ -781,7 +781,7 @@ impl Engine {
|
|||||||
id: Default::default(),
|
id: Default::default(),
|
||||||
|
|
||||||
packages: Default::default(),
|
packages: Default::default(),
|
||||||
global_module: Default::default(),
|
global_namespace: Default::default(),
|
||||||
global_sub_modules: Default::default(),
|
global_sub_modules: Default::default(),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
@ -1944,7 +1944,7 @@ impl Engine {
|
|||||||
let hash_fn = calc_native_fn_hash(empty(), op, arg_types);
|
let hash_fn = calc_native_fn_hash(empty(), op, arg_types);
|
||||||
|
|
||||||
match self
|
match self
|
||||||
.global_module
|
.global_namespace
|
||||||
.get_fn(hash_fn, false)
|
.get_fn(hash_fn, false)
|
||||||
.or_else(|| self.packages.get_fn(hash_fn))
|
.or_else(|| self.packages.get_fn(hash_fn))
|
||||||
.or_else(|| mods.get_fn(hash_fn))
|
.or_else(|| mods.get_fn(hash_fn))
|
||||||
@ -2141,7 +2141,7 @@ impl Engine {
|
|||||||
let iter_type = iter_obj.type_id();
|
let iter_type = iter_obj.type_id();
|
||||||
|
|
||||||
let func = self
|
let func = self
|
||||||
.global_module
|
.global_namespace
|
||||||
.get_iter(iter_type)
|
.get_iter(iter_type)
|
||||||
.or_else(|| self.packages.get_iter(iter_type))
|
.or_else(|| self.packages.get_iter(iter_type))
|
||||||
.or_else(|| mods.get_iter(iter_type));
|
.or_else(|| mods.get_iter(iter_type));
|
||||||
|
@ -56,8 +56,13 @@ impl Engine {
|
|||||||
+ SendSync
|
+ SendSync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.global_module
|
self.global_namespace.set_raw_fn(
|
||||||
.set_raw_fn(name, FnNamespace::Global, FnAccess::Public, arg_types, func);
|
name,
|
||||||
|
FnNamespace::Global,
|
||||||
|
FnAccess::Public,
|
||||||
|
arg_types,
|
||||||
|
func,
|
||||||
|
);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
/// Register a custom type for use with the `Engine`.
|
/// Register a custom type for use with the `Engine`.
|
||||||
@ -159,7 +164,7 @@ impl Engine {
|
|||||||
T: Variant + Clone + Iterator,
|
T: Variant + Clone + Iterator,
|
||||||
<T as Iterator>::Item: Variant + Clone,
|
<T as Iterator>::Item: Variant + Clone,
|
||||||
{
|
{
|
||||||
self.global_module.set_iterable::<T>();
|
self.global_namespace.set_iterable::<T>();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
/// 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`.
|
||||||
|
@ -176,7 +176,7 @@ impl Engine {
|
|||||||
// First search registered functions (can override packages)
|
// First search registered functions (can override packages)
|
||||||
// Then search packages
|
// Then search packages
|
||||||
let func = //lib.get_fn(hash_fn, pub_only)
|
let func = //lib.get_fn(hash_fn, pub_only)
|
||||||
self.global_module.get_fn(hash_fn, pub_only)
|
self.global_namespace.get_fn(hash_fn, pub_only)
|
||||||
.or_else(|| self.packages.get_fn(hash_fn))
|
.or_else(|| self.packages.get_fn(hash_fn))
|
||||||
.or_else(|| mods.get_fn(hash_fn));
|
.or_else(|| mods.get_fn(hash_fn));
|
||||||
|
|
||||||
@ -440,14 +440,14 @@ impl Engine {
|
|||||||
hash_script: u64,
|
hash_script: u64,
|
||||||
pub_only: bool,
|
pub_only: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// NOTE: We skip script functions for global_module and packages, and native functions for lib
|
// NOTE: We skip script functions for global_namespace and packages, and native functions for lib
|
||||||
|
|
||||||
// First check script-defined functions
|
// First check script-defined functions
|
||||||
lib.iter().any(|&m| m.contains_fn(hash_script, pub_only))
|
lib.iter().any(|&m| m.contains_fn(hash_script, pub_only))
|
||||||
//|| lib.iter().any(|&m| m.contains_fn(hash_fn, pub_only))
|
//|| lib.iter().any(|&m| m.contains_fn(hash_fn, pub_only))
|
||||||
// Then check registered functions
|
// Then check registered functions
|
||||||
//|| self.global_module.contains_fn(hash_script, pub_only)
|
//|| self.global_namespace.contains_fn(hash_script, pub_only)
|
||||||
|| self.global_module.contains_fn(hash_fn, false)
|
|| self.global_namespace.contains_fn(hash_fn, false)
|
||||||
// Then check packages
|
// Then check packages
|
||||||
|| self.packages.contains_fn(hash_script)
|
|| self.packages.contains_fn(hash_script)
|
||||||
|| self.packages.contains_fn(hash_fn)
|
|| self.packages.contains_fn(hash_fn)
|
||||||
@ -524,7 +524,7 @@ impl Engine {
|
|||||||
let func = lib
|
let func = lib
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|&m| m.get_fn(hash_script, pub_only))
|
.find_map(|&m| m.get_fn(hash_script, pub_only))
|
||||||
//.or_else(|| self.global_module.get_fn(hash_script, pub_only))
|
//.or_else(|| self.global_namespace.get_fn(hash_script, pub_only))
|
||||||
.or_else(|| self.packages.get_fn(hash_script))
|
.or_else(|| self.packages.get_fn(hash_script))
|
||||||
//.or_else(|| mods.get_fn(hash_script))
|
//.or_else(|| mods.get_fn(hash_script))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -187,7 +187,7 @@ macro_rules! def_register {
|
|||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn register_fn(&mut self, name: &str, f: FN) -> &mut Self {
|
fn register_fn(&mut self, name: &str, f: FN) -> &mut Self {
|
||||||
self.global_module.set_fn(name, FnNamespace::Global, FnAccess::Public,
|
self.global_namespace.set_fn(name, FnNamespace::Global, FnAccess::Public,
|
||||||
&[$(map_type_id::<$par>()),*],
|
&[$(map_type_id::<$par>()),*],
|
||||||
CallableFunction::$abi(make_func!(f : map_dynamic ; $($par => $let => $clone => $arg),*))
|
CallableFunction::$abi(make_func!(f : map_dynamic ; $($par => $let => $clone => $arg),*))
|
||||||
);
|
);
|
||||||
@ -202,7 +202,7 @@ macro_rules! def_register {
|
|||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn register_result_fn(&mut self, name: &str, f: FN) -> &mut Self {
|
fn register_result_fn(&mut self, name: &str, f: FN) -> &mut Self {
|
||||||
self.global_module.set_fn(name, FnNamespace::Global, FnAccess::Public,
|
self.global_namespace.set_fn(name, FnNamespace::Global, FnAccess::Public,
|
||||||
&[$(map_type_id::<$par>()),*],
|
&[$(map_type_id::<$par>()),*],
|
||||||
CallableFunction::$abi(make_func!(f : map_result ; $($par => $let => $clone => $arg),*))
|
CallableFunction::$abi(make_func!(f : map_result ; $($par => $let => $clone => $arg),*))
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user