Move blob functions to builtin.
This commit is contained in:
parent
2b79a65454
commit
9cf8360616
@ -274,6 +274,30 @@ pub fn get_builtin_binary_op_fn(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// blob
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
if type1 == TypeId::of::<crate::Blob>() {
|
||||||
|
use crate::Blob;
|
||||||
|
|
||||||
|
if type2 == TypeId::of::<INT>() {
|
||||||
|
return match op {
|
||||||
|
OP_CONTAINS => Some(|_, args| {
|
||||||
|
let range = &*args[0].read_lock::<Blob>().expect(BUILTIN);
|
||||||
|
let x = (args[1].as_int().expect("`INT`") & 0x000000ff) as u8;
|
||||||
|
Ok(range.contains(&x).into())
|
||||||
|
}),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if type1 == type2 {
|
||||||
|
return match op {
|
||||||
|
"==" => Some(impl_op!(Blob == Blob)),
|
||||||
|
"!=" => Some(impl_op!(Blob != Blob)),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// map op string
|
// map op string
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
if types_pair == (TypeId::of::<crate::Map>(), TypeId::of::<ImmutableString>()) {
|
if types_pair == (TypeId::of::<crate::Map>(), TypeId::of::<ImmutableString>()) {
|
||||||
|
@ -366,26 +366,6 @@ mod blob_functions {
|
|||||||
|
|
||||||
drained
|
drained
|
||||||
}
|
}
|
||||||
pub fn contains(blob: &mut Blob, value: Dynamic) -> bool {
|
|
||||||
if blob.is_empty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let value = match value.as_int() {
|
|
||||||
Ok(value) => value as u8,
|
|
||||||
_ => return false,
|
|
||||||
};
|
|
||||||
|
|
||||||
blob.contains(&value)
|
|
||||||
}
|
|
||||||
#[rhai_fn(name = "==", pure)]
|
|
||||||
pub fn equals(blob1: &mut Blob, blob2: Blob) -> bool {
|
|
||||||
&*blob1 == &blob2
|
|
||||||
}
|
|
||||||
#[rhai_fn(name = "!=", pure)]
|
|
||||||
pub fn not_equals(blob1: &mut Blob, blob2: Blob) -> bool {
|
|
||||||
&*blob1 != &blob2
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn parse_int(blob: &mut Blob, start: INT, len: INT, is_le: bool) -> INT {
|
fn parse_int(blob: &mut Blob, start: INT, len: INT, is_le: bool) -> INT {
|
||||||
|
@ -17,14 +17,6 @@ def_package!(crate:BasicMapPackage:"Basic object map utilities.", lib, {
|
|||||||
|
|
||||||
#[export_module]
|
#[export_module]
|
||||||
mod map_functions {
|
mod map_functions {
|
||||||
#[rhai_fn(name = "has", pure)]
|
|
||||||
pub fn contains(map: &mut Map, prop: ImmutableString) -> bool {
|
|
||||||
if map.is_empty() {
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
map.contains_key(prop.as_str())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[rhai_fn(pure)]
|
#[rhai_fn(pure)]
|
||||||
pub fn len(map: &mut Map) -> INT {
|
pub fn len(map: &mut Map) -> INT {
|
||||||
map.len() as INT
|
map.len() as INT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user