Use multiple renames to simplify plugins.
This commit is contained in:
parent
38ccb9e8f6
commit
d41fde9c31
@ -86,24 +86,16 @@ 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(get = "len")]
|
||||
#[inline(always)]
|
||||
pub fn len_prop(list: &mut Array) -> INT {
|
||||
len(list)
|
||||
}
|
||||
#[rhai_fn(name = "append", name = "+=")]
|
||||
#[inline(always)]
|
||||
pub fn append(x: &mut Array, y: Array) {
|
||||
x.extend(y);
|
||||
}
|
||||
#[rhai_fn(name = "+=")]
|
||||
#[inline(always)]
|
||||
pub fn append_operator(x: &mut Array, y: Array) {
|
||||
append(x, y)
|
||||
}
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline]
|
||||
pub fn concat(mut x: Array, y: Array) -> Array {
|
||||
|
@ -5,10 +5,13 @@ use crate::plugin::*;
|
||||
use crate::result::EvalAltResult;
|
||||
|
||||
def_package!(crate:EvalPackage:"Disable 'eval'.", lib, {
|
||||
set_exported_fn!(lib, "eval", eval_override);
|
||||
lib.combine_flatten(exported_module!(eval_override));
|
||||
});
|
||||
|
||||
#[export_fn(return_raw)]
|
||||
fn eval_override(_script: ImmutableString) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
Err("eval is evil!".into())
|
||||
#[export_module]
|
||||
mod eval_override {
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn eval(_script: ImmutableString) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
Err("eval is evil!".into())
|
||||
}
|
||||
}
|
||||
|
@ -8,14 +8,9 @@ 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()
|
||||
}
|
||||
|
||||
#[rhai_fn(get = "name")]
|
||||
#[inline(always)]
|
||||
pub fn name_prop(f: &mut FnPtr) -> ImmutableString {
|
||||
name(f)
|
||||
}
|
||||
}
|
||||
|
@ -18,33 +18,25 @@ mod map_functions {
|
||||
pub fn has(map: &mut Map, prop: ImmutableString) -> bool {
|
||||
map.contains_key(&prop)
|
||||
}
|
||||
#[rhai_fn(name = "len", get = "len")]
|
||||
#[inline(always)]
|
||||
pub fn len(map: &mut Map) -> INT {
|
||||
map.len() as INT
|
||||
}
|
||||
#[rhai_fn(get = "len")]
|
||||
#[inline(always)]
|
||||
pub fn len_prop(map: &mut Map) -> INT {
|
||||
len(map)
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn clear(map: &mut Map) {
|
||||
map.clear();
|
||||
}
|
||||
#[inline]
|
||||
#[inline(always)]
|
||||
pub fn remove(x: &mut Map, name: ImmutableString) -> Dynamic {
|
||||
x.remove(&name).unwrap_or_else(|| ().into())
|
||||
}
|
||||
#[rhai_fn(name = "mixin", name = "+=")]
|
||||
pub fn mixin(map1: &mut Map, map2: Map) {
|
||||
map2.into_iter().for_each(|(key, value)| {
|
||||
map1.insert(key, value);
|
||||
});
|
||||
}
|
||||
#[rhai_fn(name = "+=")]
|
||||
#[inline(always)]
|
||||
pub fn mixin_operator(map1: &mut Map, map2: Map) {
|
||||
mixin(map1, map2)
|
||||
}
|
||||
#[rhai_fn(name = "+")]
|
||||
pub fn merge(mut map1: Map, map2: Map) -> Map {
|
||||
map2.into_iter().for_each(|(key, value)| {
|
||||
|
@ -157,78 +157,46 @@ mod float_functions {
|
||||
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(get = "floor")]
|
||||
#[inline(always)]
|
||||
pub fn floor_prop(x: FLOAT) -> FLOAT {
|
||||
floor(x)
|
||||
}
|
||||
#[rhai_fn(name = "ceiling", get = "ceiling")]
|
||||
#[inline(always)]
|
||||
pub fn ceiling(x: FLOAT) -> FLOAT {
|
||||
x.ceil()
|
||||
}
|
||||
#[rhai_fn(get = "ceiling")]
|
||||
#[inline(always)]
|
||||
pub fn ceiling_prop(x: FLOAT) -> FLOAT {
|
||||
ceiling(x)
|
||||
}
|
||||
#[rhai_fn(name = "round", get = "round")]
|
||||
#[inline(always)]
|
||||
pub fn round(x: FLOAT) -> FLOAT {
|
||||
x.ceil()
|
||||
}
|
||||
#[rhai_fn(get = "round")]
|
||||
#[inline(always)]
|
||||
pub fn round_prop(x: FLOAT) -> FLOAT {
|
||||
ceiling(x)
|
||||
}
|
||||
#[rhai_fn(name = "int", get = "int")]
|
||||
#[inline(always)]
|
||||
pub fn int(x: FLOAT) -> FLOAT {
|
||||
x.trunc()
|
||||
}
|
||||
#[rhai_fn(get = "int")]
|
||||
#[inline(always)]
|
||||
pub fn int_prop(x: FLOAT) -> FLOAT {
|
||||
int(x)
|
||||
}
|
||||
#[rhai_fn(name = "fraction", get = "fraction")]
|
||||
#[inline(always)]
|
||||
pub fn fraction(x: FLOAT) -> FLOAT {
|
||||
x.fract()
|
||||
}
|
||||
#[rhai_fn(get = "fraction")]
|
||||
#[inline(always)]
|
||||
pub fn fraction_prop(x: FLOAT) -> FLOAT {
|
||||
fraction(x)
|
||||
}
|
||||
#[rhai_fn(name = "is_nan", get = "is_nan")]
|
||||
#[inline(always)]
|
||||
pub fn is_nan(x: FLOAT) -> bool {
|
||||
x.is_nan()
|
||||
}
|
||||
#[rhai_fn(get = "is_nan")]
|
||||
#[inline(always)]
|
||||
pub fn is_nan_prop(x: FLOAT) -> bool {
|
||||
is_nan(x)
|
||||
}
|
||||
#[rhai_fn(name = "is_finite", get = "is_finite")]
|
||||
#[inline(always)]
|
||||
pub fn is_finite(x: FLOAT) -> bool {
|
||||
x.is_finite()
|
||||
}
|
||||
#[rhai_fn(get = "is_finite")]
|
||||
#[inline(always)]
|
||||
pub fn is_finite_prop(x: FLOAT) -> bool {
|
||||
is_finite(x)
|
||||
}
|
||||
#[rhai_fn(name = "is_infinite", get = "is_infinite")]
|
||||
#[inline(always)]
|
||||
pub fn is_infinite(x: FLOAT) -> bool {
|
||||
x.is_infinite()
|
||||
}
|
||||
#[rhai_fn(get = "is_infinite")]
|
||||
#[inline(always)]
|
||||
pub fn is_infinite_prop(x: FLOAT) -> bool {
|
||||
is_infinite(x)
|
||||
}
|
||||
#[rhai_fn(name = "to_int", return_raw)]
|
||||
#[inline]
|
||||
pub fn f32_to_int(x: f32) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
|
@ -140,6 +140,7 @@ mod string_functions {
|
||||
pub fn add_prepend_unit(_x: (), s: ImmutableString) -> ImmutableString {
|
||||
s
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "+=")]
|
||||
#[inline(always)]
|
||||
pub fn append_char(s: &mut ImmutableString, ch: char) {
|
||||
@ -151,17 +152,12 @@ mod string_functions {
|
||||
*s += &add;
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "len", get = "len")]
|
||||
#[inline(always)]
|
||||
pub fn len(s: &mut ImmutableString) -> INT {
|
||||
s.chars().count() as INT
|
||||
}
|
||||
|
||||
#[rhai_fn(get = "len")]
|
||||
#[inline(always)]
|
||||
pub fn len_prop(s: &mut ImmutableString) -> INT {
|
||||
len(s)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn clear(s: &mut ImmutableString) {
|
||||
s.make_mut().clear();
|
||||
|
@ -30,7 +30,8 @@ mod time_functions {
|
||||
pub fn timestamp() -> Instant {
|
||||
Instant::now()
|
||||
}
|
||||
#[rhai_fn(return_raw)]
|
||||
|
||||
#[rhai_fn(name = "elapsed", get = "elapsed", return_raw)]
|
||||
pub fn elapsed(timestamp: &mut Instant) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
{
|
||||
@ -52,12 +53,6 @@ mod time_functions {
|
||||
}
|
||||
}
|
||||
|
||||
#[rhai_fn(get = "elapsed", return_raw)]
|
||||
#[inline(always)]
|
||||
pub fn elapsed_prop(timestamp: &mut Instant) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
elapsed(timestamp)
|
||||
}
|
||||
|
||||
#[rhai_fn(return_raw, name = "-")]
|
||||
pub fn time_diff(ts1: Instant, ts2: Instant) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
|
Loading…
Reference in New Issue
Block a user