rhai/src/plugin.rs

43 lines
1.5 KiB
Rust
Raw Normal View History

2020-09-10 11:42:34 +02:00
//! Module defining plugins in Rhai for use by plugin authors.
2020-07-02 06:47:24 +02:00
2020-08-03 02:27:19 +02:00
pub use crate::{
2020-09-10 11:42:34 +02:00
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, RegisterResultFn,
2020-08-03 02:27:19 +02:00
};
#[cfg(not(features = "no_module"))]
2020-08-03 02:27:19 +02:00
pub use rhai_codegen::*;
2020-09-10 11:42:34 +02:00
#[cfg(features = "no_module")]
pub use rhai_codegen::{export_fn, register_exported_fn};
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;
fn call(&self, args: &mut [&mut Dynamic]) -> 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
}