Move some concat functions to builtin.
This commit is contained in:
@@ -1239,8 +1239,28 @@ pub fn run_builtin_binary_op(
|
||||
use crate::packages::arithmetic::arith_basic::INT::functions::*;
|
||||
|
||||
let args_type = x.type_id();
|
||||
let second_type = y.type_id();
|
||||
|
||||
if y.type_id() != args_type {
|
||||
if second_type != args_type {
|
||||
if args_type == TypeId::of::<char>() && second_type == TypeId::of::<ImmutableString>() {
|
||||
let x = x.clone().cast::<char>();
|
||||
let y = &*y.read_lock::<ImmutableString>().unwrap();
|
||||
|
||||
match op {
|
||||
"+" => return Ok(Some(format!("{}{}", x, y).into())),
|
||||
_ => (),
|
||||
}
|
||||
} else if args_type == TypeId::of::<ImmutableString>()
|
||||
&& second_type == TypeId::of::<char>()
|
||||
{
|
||||
let x = &*x.read_lock::<ImmutableString>().unwrap();
|
||||
let y = y.clone().cast::<char>();
|
||||
|
||||
match op {
|
||||
"+" => return Ok(Some((x + y).into())),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
@@ -1317,6 +1337,7 @@ pub fn run_builtin_binary_op(
|
||||
let y = y.clone().cast::<char>();
|
||||
|
||||
match op {
|
||||
"+" => return Ok(Some(format!("{}{}", x, y).into())),
|
||||
"==" => return Ok(Some((x == y).into())),
|
||||
"!=" => return Ok(Some((x != y).into())),
|
||||
">" => return Ok(Some((x > y).into())),
|
||||
@@ -1367,8 +1388,19 @@ pub fn run_builtin_op_assignment(
|
||||
use crate::packages::arithmetic::arith_basic::INT::functions::*;
|
||||
|
||||
let args_type = x.type_id();
|
||||
let second_type = y.type_id();
|
||||
|
||||
if second_type != args_type {
|
||||
if args_type == TypeId::of::<ImmutableString>() && second_type == TypeId::of::<char>() {
|
||||
let y = y.read_lock::<char>().unwrap().deref().clone();
|
||||
let mut x = x.write_lock::<ImmutableString>().unwrap();
|
||||
|
||||
match op {
|
||||
"+=" => return Ok(Some(*x += y)),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
if y.type_id() != args_type {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
@@ -1417,6 +1449,14 @@ pub fn run_builtin_op_assignment(
|
||||
"|=" => return Ok(Some(*x = *x || y)),
|
||||
_ => (),
|
||||
}
|
||||
} else if args_type == TypeId::of::<char>() {
|
||||
let y = y.read_lock::<char>().unwrap().deref().clone();
|
||||
let mut x = x.write_lock::<Dynamic>().unwrap();
|
||||
|
||||
match op {
|
||||
"+=" => return Ok(Some(*x = format!("{}{}", *x, y).into())),
|
||||
_ => (),
|
||||
}
|
||||
} else if args_type == TypeId::of::<ImmutableString>() {
|
||||
let y = y.read_lock::<ImmutableString>().unwrap().deref().clone();
|
||||
let mut x = x.write_lock::<ImmutableString>().unwrap();
|
||||
|
||||
@@ -43,7 +43,7 @@ macro_rules! reg_functions {
|
||||
}
|
||||
|
||||
def_package!(crate:MoreStringPackage:"Additional string utilities, including string building.", lib, {
|
||||
reg_functions!(lib += basic; INT, bool, char, FnPtr);
|
||||
reg_functions!(lib += basic; INT, bool, FnPtr);
|
||||
|
||||
#[cfg(not(feature = "only_i32"))]
|
||||
#[cfg(not(feature = "only_i64"))]
|
||||
@@ -139,15 +139,6 @@ mod string_functions {
|
||||
s
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "+=")]
|
||||
pub fn append_char(s: &mut ImmutableString, ch: char) {
|
||||
*s += ch;
|
||||
}
|
||||
#[rhai_fn(name = "+=")]
|
||||
pub fn append_string(s: &mut ImmutableString, add: ImmutableString) {
|
||||
*s += &add;
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "len", get = "len")]
|
||||
pub fn len(s: &str) -> INT {
|
||||
s.chars().count() as INT
|
||||
|
||||
Reference in New Issue
Block a user