Make id_raw return Option<&ImmutableString>
This commit is contained in:
parent
e3b7aa47a0
commit
70a0d6ce58
@ -129,7 +129,7 @@ impl Imports {
|
|||||||
pub fn get_fn(
|
pub fn get_fn(
|
||||||
&self,
|
&self,
|
||||||
hash: NonZeroU64,
|
hash: NonZeroU64,
|
||||||
) -> Option<(&CallableFunction, &Option<ImmutableString>)> {
|
) -> Option<(&CallableFunction, Option<&ImmutableString>)> {
|
||||||
self.0
|
self.0
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
@ -2051,11 +2051,11 @@ impl Engine {
|
|||||||
.get_fn(hash_fn, false)
|
.get_fn(hash_fn, false)
|
||||||
.map(|f| (f, None))
|
.map(|f| (f, None))
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
self.global_modules.iter().find_map(|m| {
|
self.global_modules
|
||||||
m.get_fn(hash_fn, false).map(|f| (f, m.id_raw().as_ref()))
|
.iter()
|
||||||
|
.find_map(|m| m.get_fn(hash_fn, false).map(|f| (f, m.id_raw())))
|
||||||
})
|
})
|
||||||
})
|
.or_else(|| mods.get_fn(hash_fn))
|
||||||
.or_else(|| mods.get_fn(hash_fn).map(|(f, source)| (f, source.as_ref())))
|
|
||||||
{
|
{
|
||||||
// op= function registered as method
|
// op= function registered as method
|
||||||
Some((func, source)) if func.is_method() => {
|
Some((func, source)) if func.is_method() => {
|
||||||
|
@ -190,13 +190,12 @@ impl Engine {
|
|||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
self.global_modules.iter().find_map(|m| {
|
self.global_modules.iter().find_map(|m| {
|
||||||
m.get_fn(hash_fn, false)
|
m.get_fn(hash_fn, false)
|
||||||
.cloned()
|
.map(|f| (f.clone(), m.id_raw().cloned()))
|
||||||
.map(|f| (f, m.id_raw().clone()))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
mods.get_fn(hash_fn)
|
mods.get_fn(hash_fn)
|
||||||
.map(|(f, source)| (f.clone(), source.clone()))
|
.map(|(f, source)| (f.clone(), source.cloned()))
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -584,13 +583,13 @@ impl Engine {
|
|||||||
.iter()
|
.iter()
|
||||||
.find_map(|&m| {
|
.find_map(|&m| {
|
||||||
m.get_fn(hash_script, pub_only)
|
m.get_fn(hash_script, pub_only)
|
||||||
.map(|f| (f, m.id_raw().clone()))
|
.map(|f| (f, m.id_raw().cloned()))
|
||||||
})
|
})
|
||||||
//.or_else(|| self.global_namespace.get_fn(hash_script, pub_only))
|
//.or_else(|| self.global_namespace.get_fn(hash_script, pub_only))
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
self.global_modules.iter().find_map(|m| {
|
self.global_modules.iter().find_map(|m| {
|
||||||
m.get_fn(hash_script, false)
|
m.get_fn(hash_script, false)
|
||||||
.map(|f| (f, m.id_raw().clone()))
|
.map(|f| (f, m.id_raw().cloned()))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
//.or_else(|| mods.iter().find_map(|(_, m)| m.get_qualified_fn(hash_script).map(|f| (f, m.id_raw().clone()))))
|
//.or_else(|| mods.iter().find_map(|(_, m)| m.get_qualified_fn(hash_script).map(|f| (f, m.id_raw().clone()))))
|
||||||
@ -1224,7 +1223,7 @@ impl Engine {
|
|||||||
let new_scope = &mut Default::default();
|
let new_scope = &mut Default::default();
|
||||||
let fn_def = f.get_fn_def().clone();
|
let fn_def = f.get_fn_def().clone();
|
||||||
|
|
||||||
let mut source = module.id_raw().clone();
|
let mut source = module.id_raw().cloned();
|
||||||
mem::swap(&mut state.source, &mut source);
|
mem::swap(&mut state.source, &mut source);
|
||||||
|
|
||||||
let level = level + 1;
|
let level = level + 1;
|
||||||
@ -1237,10 +1236,10 @@ impl Engine {
|
|||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
Some(f) if f.is_plugin_fn() => f.get_plugin_fn().clone().call(
|
Some(f) if f.is_plugin_fn() => f
|
||||||
(self, module.id_raw().as_ref(), &*mods, lib).into(),
|
.get_plugin_fn()
|
||||||
args.as_mut(),
|
.clone()
|
||||||
),
|
.call((self, module.id_raw(), &*mods, lib).into(), args.as_mut()),
|
||||||
Some(f) if f.is_native() => {
|
Some(f) if f.is_native() => {
|
||||||
if !f.is_method() {
|
if !f.is_method() {
|
||||||
// Clone first argument
|
// Clone first argument
|
||||||
@ -1251,10 +1250,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f.get_native_fn()(
|
f.get_native_fn()((self, module.id_raw(), &*mods, lib).into(), args.as_mut())
|
||||||
(self, module.id_raw().as_ref(), &*mods, lib).into(),
|
|
||||||
args.as_mut(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Some(f) => unreachable!("unknown function type: {:?}", f),
|
Some(f) => unreachable!("unknown function type: {:?}", f),
|
||||||
None if def_val.is_some() => Ok(def_val.unwrap().clone()),
|
None if def_val.is_some() => Ok(def_val.unwrap().clone()),
|
||||||
|
@ -252,8 +252,8 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the ID of the [`Module`] as an [`ImmutableString`], if any.
|
/// Get the ID of the [`Module`] as an [`ImmutableString`], if any.
|
||||||
pub fn id_raw(&self) -> &Option<ImmutableString> {
|
pub fn id_raw(&self) -> Option<&ImmutableString> {
|
||||||
&self.id
|
self.id.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the ID of the [`Module`].
|
/// Set the ID of the [`Module`].
|
||||||
|
Loading…
Reference in New Issue
Block a user