Add == and != to arrays and maps.

This commit is contained in:
Stephen Chung
2020-11-08 23:00:37 +08:00
parent 487a073caf
commit 48886eacc8
9 changed files with 182 additions and 44 deletions

View File

@@ -124,6 +124,54 @@ impl<'e, 'a, 'm, 'pm> NativeCallContext<'e, 'a, 'm, 'pm> {
pub fn iter_namespaces(&self) -> impl Iterator<Item = &'pm Module> + 'm {
self.lib.iter().cloned()
}
/// Call a function inside the call context.
///
/// ## WARNING
///
/// All arguments may be _consumed_, meaning that they may be replaced by `()`.
/// This is to avoid unnecessarily cloning the arguments.
/// Do not use the arguments after this call. If they are needed afterwards,
/// clone them _before_ calling this function.
///
/// If `is_method` is `true`, the first argument is assumed to be passed
/// by reference and is not consumed.
pub fn call_fn_dynamic_raw(
&mut self,
fn_name: &str,
is_method: bool,
public_only: bool,
args: &mut [&mut Dynamic],
def_value: Option<Dynamic>,
) -> Result<Dynamic, Box<EvalAltResult>> {
let mut mods = self.mods.cloned().unwrap_or_default();
let hash_script = calc_script_fn_hash(
empty(),
fn_name,
if is_method {
args.len() - 1
} else {
args.len()
},
);
self.engine()
.exec_fn_call(
&mut mods,
&mut Default::default(),
self.lib,
fn_name,
hash_script,
args,
is_method,
is_method,
public_only,
None,
def_value,
0,
)
.map(|(r, _)| r)
}
}
/// Consume a `Shared` resource and return a mutable reference to the wrapped value.
@@ -206,12 +254,11 @@ impl FnPtr {
/// clone them _before_ calling this function.
pub fn call_dynamic(
&self,
ctx: NativeCallContext,
mut ctx: NativeCallContext,
this_ptr: Option<&mut Dynamic>,
mut arg_values: impl AsMut<[Dynamic]>,
) -> Result<Dynamic, Box<EvalAltResult>> {
let arg_values = arg_values.as_mut();
let fn_name = self.fn_name();
let mut args_data = self
.curry()
@@ -220,32 +267,15 @@ impl FnPtr {
.chain(arg_values.iter_mut().map(mem::take))
.collect::<StaticVec<_>>();
let has_this = this_ptr.is_some();
let mut args = args_data.iter_mut().collect::<StaticVec<_>>();
let hash_script = calc_script_fn_hash(empty(), fn_name, args.len());
let has_this = this_ptr.is_some();
if let Some(obj) = this_ptr {
args.insert(0, obj);
}
let mut mods = ctx.mods.cloned().unwrap_or_default();
ctx.engine()
.exec_fn_call(
&mut mods,
&mut Default::default(),
ctx.lib,
fn_name,
hash_script,
args.as_mut(),
has_this,
has_this,
true,
None,
None,
0,
)
.map(|(v, _)| v)
ctx.call_fn_dynamic_raw(self.fn_name(), has_this, true, args.as_mut(), None)
}
}