Use fluent style.
This commit is contained in:
@@ -303,19 +303,20 @@ impl<'a> NativeCallContext<'a> {
|
||||
|
||||
let mut args: StaticVec<_> = arg_values.iter_mut().collect();
|
||||
|
||||
let result = self._call_fn_raw(fn_name, &mut args, false, false, false)?;
|
||||
self._call_fn_raw(fn_name, &mut args, false, false, false)
|
||||
.and_then(|result| {
|
||||
// Bail out early if the return type needs no cast
|
||||
if TypeId::of::<T>() == TypeId::of::<Dynamic>() {
|
||||
return Ok(reify!(result => T));
|
||||
}
|
||||
|
||||
// Bail out early if the return type needs no cast
|
||||
if TypeId::of::<T>() == TypeId::of::<Dynamic>() {
|
||||
return Ok(reify!(result => T));
|
||||
}
|
||||
let typ = self.engine().map_type_name(result.type_name());
|
||||
|
||||
let typ = self.engine().map_type_name(result.type_name());
|
||||
|
||||
result.try_cast().ok_or_else(|| {
|
||||
let t = self.engine().map_type_name(type_name::<T>()).into();
|
||||
ERR::ErrorMismatchOutputType(t, typ.into(), Position::NONE).into()
|
||||
})
|
||||
result.try_cast().ok_or_else(|| {
|
||||
let t = self.engine().map_type_name(type_name::<T>()).into();
|
||||
ERR::ErrorMismatchOutputType(t, typ.into(), Position::NONE).into()
|
||||
})
|
||||
})
|
||||
}
|
||||
/// Call a registered native Rust function inside the call context with the provided arguments.
|
||||
///
|
||||
@@ -333,19 +334,20 @@ impl<'a> NativeCallContext<'a> {
|
||||
|
||||
let mut args: StaticVec<_> = arg_values.iter_mut().collect();
|
||||
|
||||
let result = self._call_fn_raw(fn_name, &mut args, true, false, false)?;
|
||||
self._call_fn_raw(fn_name, &mut args, true, false, false)
|
||||
.and_then(|result| {
|
||||
// Bail out early if the return type needs no cast
|
||||
if TypeId::of::<T>() == TypeId::of::<Dynamic>() {
|
||||
return Ok(reify!(result => T));
|
||||
}
|
||||
|
||||
// Bail out early if the return type needs no cast
|
||||
if TypeId::of::<T>() == TypeId::of::<Dynamic>() {
|
||||
return Ok(reify!(result => T));
|
||||
}
|
||||
let typ = self.engine().map_type_name(result.type_name());
|
||||
|
||||
let typ = self.engine().map_type_name(result.type_name());
|
||||
|
||||
result.try_cast().ok_or_else(|| {
|
||||
let t = self.engine().map_type_name(type_name::<T>()).into();
|
||||
ERR::ErrorMismatchOutputType(t, typ.into(), Position::NONE).into()
|
||||
})
|
||||
result.try_cast().ok_or_else(|| {
|
||||
let t = self.engine().map_type_name(type_name::<T>()).into();
|
||||
ERR::ErrorMismatchOutputType(t, typ.into(), Position::NONE).into()
|
||||
})
|
||||
})
|
||||
}
|
||||
/// Call a function (native Rust or scripted) inside the call context.
|
||||
///
|
||||
|
@@ -205,12 +205,12 @@ impl Engine {
|
||||
}
|
||||
|
||||
// First check script-defined functions
|
||||
let result = global.lib.iter().any(|m| m.contains_fn(hash_script))
|
||||
let r = global.lib.iter().any(|m| m.contains_fn(hash_script))
|
||||
// Then check the global namespace and packages
|
||||
|| self.global_modules.iter().any(|m| m.contains_fn(hash_script));
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
let result = result ||
|
||||
let r = r ||
|
||||
// Then check imported modules
|
||||
global.contains_qualified_fn(hash_script)
|
||||
// Then check sub-modules
|
||||
@@ -218,11 +218,11 @@ impl Engine {
|
||||
m.values().any(|m| m.contains_qualified_fn(hash_script))
|
||||
});
|
||||
|
||||
if !result && !cache.filter.is_absent_and_set(hash_script) {
|
||||
if !r && !cache.filter.is_absent_and_set(hash_script) {
|
||||
// Do not cache "one-hit wonders"
|
||||
cache.map.insert(hash_script, None);
|
||||
}
|
||||
|
||||
result
|
||||
r
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user