diff --git a/src/fn_native.rs b/src/fn_native.rs index 4d2cf19b..820e5dc7 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -261,7 +261,9 @@ impl CallableFunction { pub fn is_pure(&self) -> bool { match self { 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"))] Self::Script(_) => false, @@ -271,7 +273,9 @@ impl CallableFunction { pub fn is_method(&self) -> bool { match self { 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"))] Self::Script(_) => false, diff --git a/src/packages/string_more.rs b/src/packages/string_more.rs index 087e8e90..99af280d 100644 --- a/src/packages/string_more.rs +++ b/src/packages/string_more.rs @@ -22,12 +22,12 @@ macro_rules! gen_concat_functions { use super::super::*; #[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) } #[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) } } @@ -120,10 +120,10 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str ); }); -fn add_prepend(x: T, y: ImmutableString) -> String { +fn add_prepend(x: &mut T, y: ImmutableString) -> String { format!("{}{}", x, y) } -fn add_append(x: ImmutableString, y: T) -> String { +fn add_append(x: &mut ImmutableString, y: T) -> String { format!("{}{}", x, y) } diff --git a/tests/plugins.rs b/tests/plugins.rs index 3379b411..5331287b 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -7,6 +7,10 @@ use rhai::{Engine, EvalAltResult, INT}; mod special_array_package { use rhai::{Array, INT}; + #[rhai_fn(get = "foo", return_raw)] + pub fn foo(array: &mut Array) -> Result> { + Ok(array[0].clone()) + } #[rhai_fn(name = "test")] pub fn len(array: &mut Array, mul: INT) -> INT { (array.len() as INT) * mul @@ -53,6 +57,7 @@ fn test_plugins_package() -> Result<(), Box> { reg_functions!(engine += greet::single(INT, bool, char)); + assert_eq!(engine.eval::("let a = [1, 2, 3]; a.foo")?, 1); assert_eq!(engine.eval::("let a = [1, 2, 3]; test(a, 2)")?, 6); assert_eq!(engine.eval::("2 + 2")?, 5); assert_eq!(