Add/remove #[inline] attributes.
This commit is contained in:
@@ -28,7 +28,6 @@ macro_rules! gen_arithmetic_functions {
|
||||
#[export_module]
|
||||
pub mod functions {
|
||||
#[rhai_fn(name = "+", return_raw)]
|
||||
#[inline]
|
||||
pub fn add(x: $arg_type, y: $arg_type) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
x.checked_add(y).ok_or_else(|| make_err(format!("Addition overflow: {} + {}", x, y))).map(Dynamic::from)
|
||||
@@ -37,7 +36,6 @@ macro_rules! gen_arithmetic_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "-", return_raw)]
|
||||
#[inline]
|
||||
pub fn subtract(x: $arg_type, y: $arg_type) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
x.checked_sub(y).ok_or_else(|| make_err(format!("Subtraction overflow: {} - {}", x, y))).map(Dynamic::from)
|
||||
@@ -46,7 +44,6 @@ macro_rules! gen_arithmetic_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "*", return_raw)]
|
||||
#[inline]
|
||||
pub fn multiply(x: $arg_type, y: $arg_type) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
x.checked_mul(y).ok_or_else(|| make_err(format!("Multiplication overflow: {} * {}", x, y))).map(Dynamic::from)
|
||||
@@ -55,7 +52,6 @@ macro_rules! gen_arithmetic_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "/", return_raw)]
|
||||
#[inline]
|
||||
pub fn divide(x: $arg_type, y: $arg_type) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
// Detect division by zero
|
||||
@@ -69,7 +65,6 @@ macro_rules! gen_arithmetic_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "%", return_raw)]
|
||||
#[inline]
|
||||
pub fn modulo(x: $arg_type, y: $arg_type) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
x.checked_rem(y).ok_or_else(|| make_err(format!("Modulo division by zero or overflow: {} % {}", x, y))).map(Dynamic::from)
|
||||
@@ -78,7 +73,6 @@ macro_rules! gen_arithmetic_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
#[inline]
|
||||
pub fn power(x: INT, y: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
if cfg!(not(feature = "only_i32")) && y > (u32::MAX as INT) {
|
||||
@@ -94,7 +88,6 @@ macro_rules! gen_arithmetic_functions {
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "<<", return_raw)]
|
||||
#[inline]
|
||||
pub fn shift_left(x: $arg_type, y: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
if cfg!(not(feature = "only_i32")) && y > (u32::MAX as INT) {
|
||||
@@ -109,7 +102,6 @@ macro_rules! gen_arithmetic_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = ">>", return_raw)]
|
||||
#[inline]
|
||||
pub fn shift_right(x: $arg_type, y: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
if cfg!(not(feature = "only_i32")) && y > (u32::MAX as INT) {
|
||||
@@ -124,17 +116,14 @@ macro_rules! gen_arithmetic_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "&")]
|
||||
#[inline(always)]
|
||||
pub fn binary_and(x: $arg_type, y: $arg_type) -> $arg_type {
|
||||
x & y
|
||||
}
|
||||
#[rhai_fn(name = "|")]
|
||||
#[inline(always)]
|
||||
pub fn binary_or(x: $arg_type, y: $arg_type) -> $arg_type {
|
||||
x | y
|
||||
}
|
||||
#[rhai_fn(name = "^")]
|
||||
#[inline(always)]
|
||||
pub fn binary_xor(x: $arg_type, y: $arg_type) -> $arg_type {
|
||||
x ^ y
|
||||
}
|
||||
@@ -151,7 +140,6 @@ macro_rules! gen_signed_functions {
|
||||
#[export_module]
|
||||
pub mod functions {
|
||||
#[rhai_fn(name = "-", return_raw)]
|
||||
#[inline]
|
||||
pub fn neg(x: $arg_type) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
x.checked_neg().ok_or_else(|| make_err(format!("Negation overflow: -{}", x))).map(Dynamic::from)
|
||||
@@ -160,7 +148,6 @@ macro_rules! gen_signed_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(return_raw)]
|
||||
#[inline]
|
||||
pub fn abs(x: $arg_type) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) {
|
||||
x.checked_abs().ok_or_else(|| make_err(format!("Negation overflow: -{}", x))).map(Dynamic::from)
|
||||
@@ -168,7 +155,6 @@ macro_rules! gen_signed_functions {
|
||||
Ok(Dynamic::from(x.abs()))
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn sign(x: $arg_type) -> INT {
|
||||
if x == 0 {
|
||||
0
|
||||
@@ -239,40 +225,32 @@ gen_signed_functions!(signed_num_128 => i128);
|
||||
#[export_module]
|
||||
mod f32_functions {
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline(always)]
|
||||
pub fn add(x: f32, y: f32) -> f32 {
|
||||
x + y
|
||||
}
|
||||
#[rhai_fn(name = "-")]
|
||||
#[inline(always)]
|
||||
pub fn subtract(x: f32, y: f32) -> f32 {
|
||||
x - y
|
||||
}
|
||||
#[rhai_fn(name = "*")]
|
||||
#[inline(always)]
|
||||
pub fn multiply(x: f32, y: f32) -> f32 {
|
||||
x * y
|
||||
}
|
||||
#[rhai_fn(name = "/")]
|
||||
#[inline(always)]
|
||||
pub fn divide(x: f32, y: f32) -> f32 {
|
||||
x / y
|
||||
}
|
||||
#[rhai_fn(name = "%")]
|
||||
#[inline(always)]
|
||||
pub fn modulo(x: f32, y: f32) -> f32 {
|
||||
x % y
|
||||
}
|
||||
#[rhai_fn(name = "-")]
|
||||
#[inline(always)]
|
||||
pub fn neg(x: f32) -> f32 {
|
||||
-x
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn abs(x: f32) -> f32 {
|
||||
x.abs()
|
||||
}
|
||||
#[inline]
|
||||
pub fn sign(x: f32) -> INT {
|
||||
if x == 0.0 {
|
||||
0
|
||||
@@ -283,12 +261,10 @@ mod f32_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
#[inline(always)]
|
||||
pub fn pow_f_f(x: f32, y: f32) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
Ok(Dynamic::from(x.powf(y)))
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
#[inline]
|
||||
pub fn pow_f_i(x: f32, y: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) && y > (i32::MAX as INT) {
|
||||
Err(make_err(format!(
|
||||
@@ -305,15 +281,12 @@ mod f32_functions {
|
||||
#[export_module]
|
||||
mod f64_functions {
|
||||
#[rhai_fn(name = "-")]
|
||||
#[inline(always)]
|
||||
pub fn neg(x: f64) -> f64 {
|
||||
-x
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn abs(x: f64) -> f64 {
|
||||
x.abs()
|
||||
}
|
||||
#[inline]
|
||||
pub fn sign(x: f64) -> INT {
|
||||
if x == 0.0 {
|
||||
0
|
||||
@@ -324,7 +297,6 @@ mod f64_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
#[inline]
|
||||
pub fn pow_f_i(x: FLOAT, y: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) && y > (i32::MAX as INT) {
|
||||
Err(make_err(format!(
|
||||
|
||||
@@ -29,7 +29,6 @@ macro_rules! gen_array_functions {
|
||||
#[export_module]
|
||||
pub mod functions {
|
||||
#[rhai_fn(name = "push", name = "+=")]
|
||||
#[inline(always)]
|
||||
pub fn push(list: &mut Array, item: $arg_type) {
|
||||
list.push(Dynamic::from(item));
|
||||
}
|
||||
@@ -89,22 +88,18 @@ def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, {
|
||||
#[export_module]
|
||||
mod array_functions {
|
||||
#[rhai_fn(name = "len", get = "len")]
|
||||
#[inline(always)]
|
||||
pub fn len(list: &mut Array) -> INT {
|
||||
list.len() as INT
|
||||
}
|
||||
#[rhai_fn(name = "append", name = "+=")]
|
||||
#[inline(always)]
|
||||
pub fn append(x: &mut Array, y: Array) {
|
||||
x.extend(y);
|
||||
}
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline]
|
||||
pub fn concat(mut x: Array, y: Array) -> Array {
|
||||
x.extend(y);
|
||||
x
|
||||
}
|
||||
#[inline]
|
||||
pub fn pop(list: &mut Array) -> Dynamic {
|
||||
list.pop().unwrap_or_else(|| ().into())
|
||||
}
|
||||
@@ -122,7 +117,6 @@ mod array_functions {
|
||||
list.remove(len as usize)
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn clear(list: &mut Array) {
|
||||
list.clear();
|
||||
}
|
||||
@@ -133,7 +127,6 @@ mod array_functions {
|
||||
list.clear();
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn reverse(list: &mut Array) {
|
||||
list.reverse();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ def_package!(crate:BasicFnPackage:"Basic Fn functions.", lib, {
|
||||
#[export_module]
|
||||
mod fn_ptr_functions {
|
||||
#[rhai_fn(name = "name", get = "name")]
|
||||
#[inline(always)]
|
||||
pub fn name(f: &mut FnPtr) -> ImmutableString {
|
||||
f.get_fn_name().clone()
|
||||
}
|
||||
|
||||
@@ -9,32 +9,26 @@ macro_rules! gen_cmp_functions {
|
||||
#[export_module]
|
||||
pub mod functions {
|
||||
#[rhai_fn(name = "<")]
|
||||
#[inline(always)]
|
||||
pub fn lt(x: $arg_type, y: $arg_type) -> bool {
|
||||
x < y
|
||||
}
|
||||
#[rhai_fn(name = "<=")]
|
||||
#[inline(always)]
|
||||
pub fn lte(x: $arg_type, y: $arg_type) -> bool {
|
||||
x <= y
|
||||
}
|
||||
#[rhai_fn(name = ">")]
|
||||
#[inline(always)]
|
||||
pub fn gt(x: $arg_type, y: $arg_type) -> bool {
|
||||
x > y
|
||||
}
|
||||
#[rhai_fn(name = ">=")]
|
||||
#[inline(always)]
|
||||
pub fn gte(x: $arg_type, y: $arg_type) -> bool {
|
||||
x >= y
|
||||
}
|
||||
#[rhai_fn(name = "==")]
|
||||
#[inline(always)]
|
||||
pub fn eq(x: $arg_type, y: $arg_type) -> bool {
|
||||
x == y
|
||||
}
|
||||
#[rhai_fn(name = "!=")]
|
||||
#[inline(always)]
|
||||
pub fn ne(x: $arg_type, y: $arg_type) -> bool {
|
||||
x != y
|
||||
}
|
||||
@@ -67,7 +61,6 @@ def_package!(crate:LogicPackage:"Logical operators.", lib, {
|
||||
|
||||
// Logic operators
|
||||
#[export_fn]
|
||||
#[inline(always)]
|
||||
fn not(x: bool) -> bool {
|
||||
!x
|
||||
}
|
||||
|
||||
@@ -14,19 +14,15 @@ def_package!(crate:BasicMapPackage:"Basic object map utilities.", lib, {
|
||||
|
||||
#[export_module]
|
||||
mod map_functions {
|
||||
#[inline(always)]
|
||||
pub fn has(map: &mut Map, prop: ImmutableString) -> bool {
|
||||
map.contains_key(&prop)
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn len(map: &mut Map) -> INT {
|
||||
map.len() as INT
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn clear(map: &mut Map) {
|
||||
map.clear();
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn remove(x: &mut Map, name: ImmutableString) -> Dynamic {
|
||||
x.remove(&name).unwrap_or_else(|| ().into())
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ macro_rules! gen_conversion_functions {
|
||||
use super::super::*;
|
||||
|
||||
#[export_fn]
|
||||
#[inline(always)]
|
||||
pub fn $func_name(x: $arg_type) -> $result_type {
|
||||
x as $result_type
|
||||
}
|
||||
@@ -86,51 +85,39 @@ def_package!(crate:BasicMathPackage:"Basic mathematic functions.", lib, {
|
||||
mod trig_functions {
|
||||
use crate::parser::FLOAT;
|
||||
|
||||
#[inline(always)]
|
||||
pub fn sin(x: FLOAT) -> FLOAT {
|
||||
x.to_radians().sin()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn cos(x: FLOAT) -> FLOAT {
|
||||
x.to_radians().cos()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn tan(x: FLOAT) -> FLOAT {
|
||||
x.to_radians().tan()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn sinh(x: FLOAT) -> FLOAT {
|
||||
x.to_radians().sinh()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn cosh(x: FLOAT) -> FLOAT {
|
||||
x.to_radians().cosh()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn tanh(x: FLOAT) -> FLOAT {
|
||||
x.to_radians().tanh()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn asin(x: FLOAT) -> FLOAT {
|
||||
x.asin().to_degrees()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn acos(x: FLOAT) -> FLOAT {
|
||||
x.acos().to_degrees()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn atan(x: FLOAT) -> FLOAT {
|
||||
x.atan().to_degrees()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn asinh(x: FLOAT) -> FLOAT {
|
||||
x.asinh().to_degrees()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn acosh(x: FLOAT) -> FLOAT {
|
||||
x.acosh().to_degrees()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn atanh(x: FLOAT) -> FLOAT {
|
||||
x.atanh().to_degrees()
|
||||
}
|
||||
@@ -141,68 +128,54 @@ mod trig_functions {
|
||||
mod float_functions {
|
||||
use crate::parser::FLOAT;
|
||||
|
||||
#[inline(always)]
|
||||
pub fn sqrt(x: FLOAT) -> FLOAT {
|
||||
x.sqrt()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn exp(x: FLOAT) -> FLOAT {
|
||||
x.exp()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn ln(x: FLOAT) -> FLOAT {
|
||||
x.ln()
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn log(x: FLOAT, base: FLOAT) -> FLOAT {
|
||||
x.log(base)
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn log10(x: FLOAT) -> FLOAT {
|
||||
x.log10()
|
||||
}
|
||||
#[rhai_fn(name = "floor", get = "floor")]
|
||||
#[inline(always)]
|
||||
pub fn floor(x: FLOAT) -> FLOAT {
|
||||
x.floor()
|
||||
}
|
||||
#[rhai_fn(name = "ceiling", get = "ceiling")]
|
||||
#[inline(always)]
|
||||
pub fn ceiling(x: FLOAT) -> FLOAT {
|
||||
x.ceil()
|
||||
}
|
||||
#[rhai_fn(name = "round", get = "round")]
|
||||
#[inline(always)]
|
||||
pub fn round(x: FLOAT) -> FLOAT {
|
||||
x.ceil()
|
||||
}
|
||||
#[rhai_fn(name = "int", get = "int")]
|
||||
#[inline(always)]
|
||||
pub fn int(x: FLOAT) -> FLOAT {
|
||||
x.trunc()
|
||||
}
|
||||
#[rhai_fn(name = "fraction", get = "fraction")]
|
||||
#[inline(always)]
|
||||
pub fn fraction(x: FLOAT) -> FLOAT {
|
||||
x.fract()
|
||||
}
|
||||
#[rhai_fn(name = "is_nan", get = "is_nan")]
|
||||
#[inline(always)]
|
||||
pub fn is_nan(x: FLOAT) -> bool {
|
||||
x.is_nan()
|
||||
}
|
||||
#[rhai_fn(name = "is_finite", get = "is_finite")]
|
||||
#[inline(always)]
|
||||
pub fn is_finite(x: FLOAT) -> bool {
|
||||
x.is_finite()
|
||||
}
|
||||
#[rhai_fn(name = "is_infinite", get = "is_infinite")]
|
||||
#[inline(always)]
|
||||
pub fn is_infinite(x: FLOAT) -> bool {
|
||||
x.is_infinite()
|
||||
}
|
||||
#[rhai_fn(name = "to_int", return_raw)]
|
||||
#[inline]
|
||||
pub fn f32_to_int(x: f32) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f32) {
|
||||
EvalAltResult::ErrorArithmetic(
|
||||
@@ -215,7 +188,6 @@ mod float_functions {
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "to_int", return_raw)]
|
||||
#[inline]
|
||||
pub fn f64_to_int(x: f64) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f64) {
|
||||
EvalAltResult::ErrorArithmetic(
|
||||
@@ -229,7 +201,6 @@ mod float_functions {
|
||||
}
|
||||
|
||||
#[rhai_fn(return_raw)]
|
||||
#[inline]
|
||||
pub fn parse_float(s: &str) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
s.trim()
|
||||
.parse::<FLOAT>()
|
||||
@@ -291,7 +262,6 @@ fn parse_int_radix(s: &str, radix: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
}
|
||||
|
||||
#[export_fn(return_raw)]
|
||||
#[inline(always)]
|
||||
fn parse_int(s: &str) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
parse_int_radix(s, 10)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ macro_rules! gen_functions {
|
||||
use super::super::*;
|
||||
|
||||
#[export_fn]
|
||||
#[inline(always)]
|
||||
pub fn to_string_func(x: &mut $arg_type) -> ImmutableString {
|
||||
super::super::$fn_name(x)
|
||||
}
|
||||
@@ -124,30 +123,24 @@ gen_functions!(print_array => to_debug(Array));
|
||||
|
||||
// Register print and debug
|
||||
#[export_fn]
|
||||
#[inline(always)]
|
||||
fn print_empty_string() -> ImmutableString {
|
||||
"".to_string().into()
|
||||
}
|
||||
#[export_fn]
|
||||
#[inline(always)]
|
||||
fn print_unit(_x: ()) -> ImmutableString {
|
||||
"".to_string().into()
|
||||
}
|
||||
#[export_fn]
|
||||
#[inline(always)]
|
||||
fn print_string(s: ImmutableString) -> ImmutableString {
|
||||
s
|
||||
}
|
||||
#[export_fn]
|
||||
#[inline(always)]
|
||||
fn debug_fn_ptr(f: &mut FnPtr) -> ImmutableString {
|
||||
to_string(f)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn to_string<T: Display>(x: &mut T) -> ImmutableString {
|
||||
x.to_string().into()
|
||||
}
|
||||
#[inline]
|
||||
fn to_debug<T: Debug>(x: &mut T) -> ImmutableString {
|
||||
format!("{:?}", x).into()
|
||||
}
|
||||
@@ -155,7 +148,7 @@ fn to_debug<T: Debug>(x: &mut T) -> ImmutableString {
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
mod format_map {
|
||||
use super::*;
|
||||
#[inline]
|
||||
|
||||
#[export_fn]
|
||||
pub fn format_map(x: &mut Map) -> ImmutableString {
|
||||
format!("#{:?}", x).into()
|
||||
|
||||
@@ -23,13 +23,11 @@ macro_rules! gen_concat_functions {
|
||||
#[export_module]
|
||||
pub mod functions {
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline]
|
||||
pub fn append_func(x: &str, y: $arg_type) -> String {
|
||||
format!("{}{}", x, y)
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline]
|
||||
pub fn prepend_func(x: &mut $arg_type, y: &str) -> String {
|
||||
format!("{}{}", x, y)
|
||||
}
|
||||
@@ -133,34 +131,28 @@ gen_concat_functions!(float => f32, f64);
|
||||
#[export_module]
|
||||
mod string_functions {
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline(always)]
|
||||
pub fn add_append_unit(s: ImmutableString, _x: ()) -> ImmutableString {
|
||||
s
|
||||
}
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline(always)]
|
||||
pub fn add_prepend_unit(_x: (), s: ImmutableString) -> ImmutableString {
|
||||
s
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "+=")]
|
||||
#[inline(always)]
|
||||
pub fn append_char(s: &mut ImmutableString, ch: char) {
|
||||
*s += ch;
|
||||
}
|
||||
#[rhai_fn(name = "+=")]
|
||||
#[inline(always)]
|
||||
pub fn append_string(s: &mut ImmutableString, add: ImmutableString) {
|
||||
*s += &add;
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "len", get = "len")]
|
||||
#[inline(always)]
|
||||
pub fn len(s: &str) -> INT {
|
||||
s.chars().count() as INT
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn clear(s: &mut ImmutableString) {
|
||||
s.make_mut().clear();
|
||||
}
|
||||
@@ -183,11 +175,9 @@ mod string_functions {
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "contains")]
|
||||
#[inline(always)]
|
||||
pub fn contains_char(s: &str, ch: char) -> bool {
|
||||
s.contains(ch)
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn contains(s: &str, find: ImmutableString) -> bool {
|
||||
s.contains(find.as_str())
|
||||
}
|
||||
@@ -263,7 +253,6 @@ mod string_functions {
|
||||
.into()
|
||||
}
|
||||
#[rhai_fn(name = "sub_string")]
|
||||
#[inline(always)]
|
||||
pub fn sub_string_starting_from(s: &str, start: INT) -> ImmutableString {
|
||||
let len = s.len() as INT;
|
||||
sub_string(s, start, len)
|
||||
@@ -296,28 +285,23 @@ mod string_functions {
|
||||
copy.extend(chars.iter().skip(offset).take(len));
|
||||
}
|
||||
#[rhai_fn(name = "crop")]
|
||||
#[inline(always)]
|
||||
pub fn crop_string_starting_from(s: &mut ImmutableString, start: INT) {
|
||||
crop(s, start, s.len() as INT);
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "replace")]
|
||||
#[inline(always)]
|
||||
pub fn replace(s: &mut ImmutableString, find: ImmutableString, sub: ImmutableString) {
|
||||
*s = s.replace(find.as_str(), sub.as_str()).into();
|
||||
}
|
||||
#[rhai_fn(name = "replace")]
|
||||
#[inline(always)]
|
||||
pub fn replace_string_with_char(s: &mut ImmutableString, find: ImmutableString, sub: char) {
|
||||
*s = s.replace(find.as_str(), &sub.to_string()).into();
|
||||
}
|
||||
#[rhai_fn(name = "replace")]
|
||||
#[inline(always)]
|
||||
pub fn replace_char_with_string(s: &mut ImmutableString, find: char, sub: ImmutableString) {
|
||||
*s = s.replace(&find.to_string(), sub.as_str()).into();
|
||||
}
|
||||
#[rhai_fn(name = "replace")]
|
||||
#[inline(always)]
|
||||
pub fn replace_char(s: &mut ImmutableString, find: char, sub: char) {
|
||||
*s = s.replace(&find.to_string(), &sub.to_string()).into();
|
||||
}
|
||||
@@ -327,24 +311,20 @@ mod string_functions {
|
||||
use crate::engine::Array;
|
||||
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline]
|
||||
pub fn append(x: &str, y: Array) -> String {
|
||||
format!("{}{:?}", x, y)
|
||||
}
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline]
|
||||
pub fn prepend(x: &mut Array, y: &str) -> String {
|
||||
format!("{:?}{}", x, y)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn split(s: &str, delimiter: ImmutableString) -> Array {
|
||||
s.split(delimiter.as_str())
|
||||
.map(Into::<Dynamic>::into)
|
||||
.collect()
|
||||
}
|
||||
#[rhai_fn(name = "split")]
|
||||
#[inline(always)]
|
||||
pub fn split_char(s: &str, delimiter: char) -> Array {
|
||||
s.split(delimiter).map(Into::<Dynamic>::into).collect()
|
||||
}
|
||||
@@ -355,12 +335,10 @@ mod string_functions {
|
||||
use crate::engine::Map;
|
||||
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline]
|
||||
pub fn append(x: &str, y: Map) -> String {
|
||||
format!("{}#{:?}", x, y)
|
||||
}
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline]
|
||||
pub fn prepend(x: &mut Map, y: &str) -> String {
|
||||
format!("#{:?}{}", x, y)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ def_package!(crate:BasicTimePackage:"Basic timing utilities.", lib, {
|
||||
|
||||
#[export_module]
|
||||
mod time_functions {
|
||||
#[inline(always)]
|
||||
pub fn timestamp() -> Instant {
|
||||
Instant::now()
|
||||
}
|
||||
@@ -212,32 +211,26 @@ mod time_functions {
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "==")]
|
||||
#[inline(always)]
|
||||
pub fn eq(x: Instant, y: Instant) -> bool {
|
||||
x == y
|
||||
}
|
||||
#[rhai_fn(name = "!=")]
|
||||
#[inline(always)]
|
||||
pub fn ne(x: Instant, y: Instant) -> bool {
|
||||
x != y
|
||||
}
|
||||
#[rhai_fn(name = "<")]
|
||||
#[inline(always)]
|
||||
pub fn lt(x: Instant, y: Instant) -> bool {
|
||||
x < y
|
||||
}
|
||||
#[rhai_fn(name = "<=")]
|
||||
#[inline(always)]
|
||||
pub fn lte(x: Instant, y: Instant) -> bool {
|
||||
x <= y
|
||||
}
|
||||
#[rhai_fn(name = ">")]
|
||||
#[inline(always)]
|
||||
pub fn gt(x: Instant, y: Instant) -> bool {
|
||||
x > y
|
||||
}
|
||||
#[rhai_fn(name = ">=")]
|
||||
#[inline(always)]
|
||||
pub fn gte(x: Instant, y: Instant) -> bool {
|
||||
x >= y
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user