Merge branch 'plugins_dev' into plugins
This commit is contained in:
commit
9e7516ba27
@ -261,7 +261,9 @@ impl CallableFunction {
|
|||||||
pub fn is_pure(&self) -> bool {
|
pub fn is_pure(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(_) => true,
|
Self::Pure(_) => true,
|
||||||
Self::Method(_) | Self::Iterator(_) | Self::Plugin(_) => false,
|
Self::Method(_) | Self::Iterator(_) => false,
|
||||||
|
|
||||||
|
Self::Plugin(p) => !p.is_method_call(),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(_) => false,
|
Self::Script(_) => false,
|
||||||
@ -271,7 +273,9 @@ impl CallableFunction {
|
|||||||
pub fn is_method(&self) -> bool {
|
pub fn is_method(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Method(_) => true,
|
Self::Method(_) => true,
|
||||||
Self::Pure(_) | Self::Iterator(_) | Self::Plugin(_) => false,
|
Self::Pure(_) | Self::Iterator(_) => false,
|
||||||
|
|
||||||
|
Self::Plugin(p) => p.is_method_call(),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(_) => false,
|
Self::Script(_) => false,
|
||||||
|
@ -22,12 +22,12 @@ macro_rules! gen_concat_functions {
|
|||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
#[export_fn]
|
#[export_fn]
|
||||||
pub fn append_func(x: ImmutableString, y: $arg_type) -> String {
|
pub fn append_func(x: &mut ImmutableString, y: $arg_type) -> String {
|
||||||
super::super::add_append(x, y)
|
super::super::add_append(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export_fn]
|
#[export_fn]
|
||||||
pub fn prepend_func(x: $arg_type, y: ImmutableString) -> String {
|
pub fn prepend_func(x: &mut $arg_type, y: ImmutableString) -> String {
|
||||||
super::super::add_prepend(x, y)
|
super::super::add_prepend(x, y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,10 +120,10 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
fn add_prepend<T: Display>(x: T, y: ImmutableString) -> String {
|
fn add_prepend<T: Display>(x: &mut T, y: ImmutableString) -> String {
|
||||||
format!("{}{}", x, y)
|
format!("{}{}", x, y)
|
||||||
}
|
}
|
||||||
fn add_append<T: Display>(x: ImmutableString, y: T) -> String {
|
fn add_append<T: Display>(x: &mut ImmutableString, y: T) -> String {
|
||||||
format!("{}{}", x, y)
|
format!("{}{}", x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,10 @@ use rhai::{Engine, EvalAltResult, INT};
|
|||||||
mod special_array_package {
|
mod special_array_package {
|
||||||
use rhai::{Array, INT};
|
use rhai::{Array, INT};
|
||||||
|
|
||||||
|
#[rhai_fn(get = "foo", return_raw)]
|
||||||
|
pub fn foo(array: &mut Array) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||||
|
Ok(array[0].clone())
|
||||||
|
}
|
||||||
#[rhai_fn(name = "test")]
|
#[rhai_fn(name = "test")]
|
||||||
pub fn len(array: &mut Array, mul: INT) -> INT {
|
pub fn len(array: &mut Array, mul: INT) -> INT {
|
||||||
(array.len() as INT) * mul
|
(array.len() as INT) * mul
|
||||||
@ -53,6 +57,7 @@ fn test_plugins_package() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
reg_functions!(engine += greet::single(INT, bool, char));
|
reg_functions!(engine += greet::single(INT, bool, char));
|
||||||
|
|
||||||
|
assert_eq!(engine.eval::<INT>("let a = [1, 2, 3]; a.foo")?, 1);
|
||||||
assert_eq!(engine.eval::<INT>("let a = [1, 2, 3]; test(a, 2)")?, 6);
|
assert_eq!(engine.eval::<INT>("let a = [1, 2, 3]; test(a, 2)")?, 6);
|
||||||
assert_eq!(engine.eval::<INT>("2 + 2")?, 5);
|
assert_eq!(engine.eval::<INT>("2 + 2")?, 5);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user