Merge branch 'plugins_dev' of https://github.com/schungx/rhai into plugins
This commit is contained in:
@@ -1136,6 +1136,7 @@ impl Dynamic {
|
||||
}
|
||||
|
||||
/// Convert the `Dynamic` into `String` and return it.
|
||||
/// If there are other references to the same string, a cloned copy is returned.
|
||||
/// Returns the name of the actual type if the cast fails.
|
||||
#[inline(always)]
|
||||
pub fn take_string(self) -> Result<String, &'static str> {
|
||||
@@ -1145,7 +1146,8 @@ impl Dynamic {
|
||||
|
||||
/// Convert the `Dynamic` into `ImmutableString` and return it.
|
||||
/// Returns the name of the actual type if the cast fails.
|
||||
pub(crate) fn take_immutable_string(self) -> Result<ImmutableString, &'static str> {
|
||||
#[inline]
|
||||
pub fn take_immutable_string(self) -> Result<ImmutableString, &'static str> {
|
||||
match self.0 {
|
||||
Union::Str(s) => Ok(s),
|
||||
Union::FnPtr(f) => Ok(f.take_data().0),
|
||||
|
@@ -232,7 +232,7 @@ impl Engine {
|
||||
|
||||
// Run external function
|
||||
let result = if func.is_plugin_fn() {
|
||||
func.get_plugin_fn().call(args, Position::none())
|
||||
func.get_plugin_fn().call(args)
|
||||
} else {
|
||||
func.get_native_fn()(self, lib, args)
|
||||
};
|
||||
@@ -1099,7 +1099,7 @@ impl Engine {
|
||||
|
||||
self.call_script_fn(scope, mods, state, lib, &mut None, name, func, args, level)
|
||||
}
|
||||
Some(f) if f.is_plugin_fn() => f.get_plugin_fn().call(args.as_mut(), Position::none()),
|
||||
Some(f) if f.is_plugin_fn() => f.get_plugin_fn().call(args.as_mut()),
|
||||
Some(f) if f.is_native() => {
|
||||
if !f.is_method() {
|
||||
// Clone first argument
|
||||
|
@@ -46,7 +46,7 @@ pub trait RegisterPlugin<PL: crate::plugin::Plugin> {
|
||||
/// fn is_method_call(&self) -> bool { false }
|
||||
/// fn is_varadic(&self) -> bool { false }
|
||||
///
|
||||
/// fn call(&self, args: &mut[&mut Dynamic], pos: Position) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
/// fn call(&self, args: &mut[&mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
/// let x1: NUMBER = std::mem::take(args[0]).clone().cast::<NUMBER>();
|
||||
/// let y1: NUMBER = std::mem::take(args[1]).clone().cast::<NUMBER>();
|
||||
/// let x2: NUMBER = std::mem::take(args[2]).clone().cast::<NUMBER>();
|
||||
|
@@ -3,7 +3,7 @@
|
||||
pub use crate::{
|
||||
fn_native::CallableFunction, stdlib::any::TypeId, stdlib::boxed::Box, stdlib::format,
|
||||
stdlib::mem, stdlib::string::ToString, stdlib::vec as new_vec, stdlib::vec::Vec, Dynamic,
|
||||
Engine, EvalAltResult, FnAccess, ImmutableString, Module, Position, RegisterResultFn,
|
||||
Engine, EvalAltResult, FnAccess, ImmutableString, Module, RegisterResultFn,
|
||||
};
|
||||
|
||||
#[cfg(not(features = "no_module"))]
|
||||
@@ -34,8 +34,7 @@ pub trait PluginFunction {
|
||||
fn is_method_call(&self) -> bool;
|
||||
fn is_varadic(&self) -> bool;
|
||||
|
||||
fn call(&self, args: &mut [&mut Dynamic], pos: Position)
|
||||
-> Result<Dynamic, Box<EvalAltResult>>;
|
||||
fn call(&self, args: &mut [&mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>;
|
||||
|
||||
fn clone_boxed(&self) -> Box<dyn PluginFunction>;
|
||||
|
||||
|
Reference in New Issue
Block a user