2020-07-02 06:47:24 +02:00
|
|
|
//! Module defining plugins in Rhai. Is exported for use by plugin authors.
|
|
|
|
|
2020-08-01 18:52:26 +02:00
|
|
|
use crate::stdlib::{any::TypeId, boxed::Box};
|
2020-07-29 23:56:29 +02:00
|
|
|
|
2020-08-02 12:53:25 +02:00
|
|
|
use crate::any::Dynamic;
|
|
|
|
use crate::engine::Engine;
|
|
|
|
pub use crate::fn_native::CallableFunction;
|
|
|
|
use crate::result::EvalAltResult;
|
|
|
|
use crate::token::Position;
|
2020-07-02 06:47:24 +02:00
|
|
|
|
|
|
|
#[cfg(features = "sync")]
|
|
|
|
/// Represents an externally-written plugin for the Rhai interpreter.
|
|
|
|
///
|
|
|
|
/// This trait should not be used directly. Use the `#[plugin]` procedural attribute instead.
|
|
|
|
pub trait Plugin: Send {
|
|
|
|
fn register_contents(self, engine: &mut Engine);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(features = "sync"))]
|
|
|
|
/// Represents an externally-written plugin for the Rhai interpreter.
|
|
|
|
///
|
|
|
|
/// This trait should not be used directly. Use the `#[plugin]` procedural attribute instead.
|
|
|
|
pub trait Plugin: Send + Sync {
|
|
|
|
fn register_contents(self, engine: &mut Engine);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Represents a function that is statically defined within a plugin.
|
|
|
|
///
|
|
|
|
/// This trait should not be used directly. Use the `#[plugin]` procedural attribute instead.
|
|
|
|
pub trait PluginFunction {
|
|
|
|
fn is_method_call(&self) -> bool;
|
|
|
|
fn is_varadic(&self) -> bool;
|
|
|
|
|
2020-08-02 12:53:25 +02:00
|
|
|
fn call(&self, args: &mut [&mut Dynamic], pos: Position)
|
|
|
|
-> Result<Dynamic, Box<EvalAltResult>>;
|
2020-07-02 06:47:24 +02:00
|
|
|
|
|
|
|
fn clone_boxed(&self) -> Box<dyn PluginFunction>;
|
2020-08-01 18:52:26 +02:00
|
|
|
|
|
|
|
fn input_types(&self) -> Box<[TypeId]>;
|
2020-07-02 06:47:24 +02:00
|
|
|
}
|