Fix array bug.
This commit is contained in:
parent
3751b6d018
commit
5c31ec7f78
@ -656,7 +656,35 @@ pub fn get_builtin_op_assignment_fn(
|
|||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Blob op= int
|
|
||||||
|
// array op= any
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
if type1 == TypeId::of::<crate::Array>() {
|
||||||
|
use crate::packages::array_basic::array_functions::*;
|
||||||
|
use crate::Array;
|
||||||
|
|
||||||
|
if type2 == TypeId::of::<crate::Array>() {
|
||||||
|
return match op {
|
||||||
|
"+=" => Some(|_, args| {
|
||||||
|
let array2 = std::mem::take(args[1]).cast::<Array>();
|
||||||
|
let array1 = &mut *args[0].write_lock::<Array>().expect(BUILTIN);
|
||||||
|
Ok(append(array1, array2).into())
|
||||||
|
}),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return match op {
|
||||||
|
"+=" => Some(|_, args| {
|
||||||
|
let x = std::mem::take(args[1]);
|
||||||
|
let array = &mut *args[0].write_lock::<Array>().expect(BUILTIN);
|
||||||
|
Ok(push(array, x).into())
|
||||||
|
}),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// blob op= int
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
if types_pair == (TypeId::of::<crate::Blob>(), TypeId::of::<INT>()) {
|
if types_pair == (TypeId::of::<crate::Blob>(), TypeId::of::<INT>()) {
|
||||||
use crate::Blob;
|
use crate::Blob;
|
||||||
@ -752,21 +780,6 @@ pub fn get_builtin_op_assignment_fn(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_index"))]
|
|
||||||
if type1 == TypeId::of::<crate::Array>() {
|
|
||||||
use crate::packages::array_basic::array_functions::*;
|
|
||||||
use crate::Array;
|
|
||||||
|
|
||||||
return match op {
|
|
||||||
"+=" => Some(|_, args| {
|
|
||||||
let array2 = std::mem::take(args[1]).cast::<Array>();
|
|
||||||
let array1 = &mut *args[0].write_lock::<Array>().expect(BUILTIN);
|
|
||||||
Ok(append(array1, array2).into())
|
|
||||||
}),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
if type1 == TypeId::of::<crate::Blob>() {
|
if type1 == TypeId::of::<crate::Blob>() {
|
||||||
use crate::packages::blob_basic::blob_functions::*;
|
use crate::packages::blob_basic::blob_functions::*;
|
||||||
|
@ -29,11 +29,9 @@ pub mod array_functions {
|
|||||||
pub fn len(array: &mut Array) -> INT {
|
pub fn len(array: &mut Array) -> INT {
|
||||||
array.len() as INT
|
array.len() as INT
|
||||||
}
|
}
|
||||||
#[rhai_fn(name = "push", name = "+=")]
|
|
||||||
pub fn push(array: &mut Array, item: Dynamic) {
|
pub fn push(array: &mut Array, item: Dynamic) {
|
||||||
array.push(item);
|
array.push(item);
|
||||||
}
|
}
|
||||||
#[rhai_fn(name = "append")]
|
|
||||||
pub fn append(array1: &mut Array, array2: Array) {
|
pub fn append(array1: &mut Array, array2: Array) {
|
||||||
if !array2.is_empty() {
|
if !array2.is_empty() {
|
||||||
if array1.is_empty() {
|
if array1.is_empty() {
|
||||||
|
@ -1110,9 +1110,9 @@ fn parse_switch(
|
|||||||
value.hash(hasher);
|
value.hash(hasher);
|
||||||
let hash = hasher.finish();
|
let hash = hasher.finish();
|
||||||
|
|
||||||
if !table.contains_key(&hash) {
|
table
|
||||||
table.insert(hash, (condition.clone(), stmt.into()).into());
|
.entry(hash)
|
||||||
}
|
.or_insert_with(|| (condition.clone(), stmt.into()).into());
|
||||||
}
|
}
|
||||||
// Other range
|
// Other range
|
||||||
_ => ranges.push((range.0, range.1, range.2, condition, stmt.into())),
|
_ => ranges.push((range.0, range.1, range.2, condition, stmt.into())),
|
||||||
|
Loading…
Reference in New Issue
Block a user