rhai/src/plugin.rs

43 lines
1.4 KiB
Rust
Raw Normal View History

//! Module defining macros for developing _plugins_.
2020-07-02 06:47:24 +02:00
2020-10-29 04:37:51 +01:00
pub use crate::ast::FnAccess;
2020-10-28 15:18:44 +01:00
pub use crate::dynamic::Dynamic;
pub use crate::engine::Engine;
pub use crate::fn_native::{CallableFunction, FnCallArgs, NativeCallContext};
pub use crate::fn_register::{RegisterFn, RegisterResultFn};
pub use crate::module::Module;
pub use crate::result::EvalAltResult;
pub use crate::utils::ImmutableString;
2020-09-30 17:27:41 +02:00
pub use crate::stdlib::{any::TypeId, boxed::Box, format, mem, string::ToString, vec as new_vec};
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
/// Trait implemented by a _plugin function_.
/// This trait should not be used directly.
2020-07-02 06:47:24 +02:00
///
/// Use the `#[export_module]` and `#[export_fn]` procedural attributes instead.
2020-07-02 06:47:24 +02:00
pub trait PluginFunction {
/// Call the plugin function with the arguments provided.
fn call(
&self,
context: NativeCallContext,
args: &mut FnCallArgs,
) -> Result<Dynamic, Box<EvalAltResult>>;
/// Is this plugin function a method?
2020-07-02 06:47:24 +02:00
fn is_method_call(&self) -> bool;
/// Is this plugin function variadic?
fn is_variadic(&self) -> bool;
2020-07-02 06:47:24 +02:00
/// Convert a plugin function into a boxed trait object.
2020-07-02 06:47:24 +02:00
fn clone_boxed(&self) -> Box<dyn PluginFunction>;
2020-08-01 18:52:26 +02:00
/// Return a boxed slice of type ID's of the function's parameters.
2020-08-01 18:52:26 +02:00
fn input_types(&self) -> Box<[TypeId]>;
2020-07-02 06:47:24 +02:00
}