rhai/src/plugin.rs

42 lines
1.5 KiB
Rust
Raw Normal View History

//! Module defining macros for developing _plugins_.
2020-07-02 06:47:24 +02:00
2020-11-16 16:10:14 +01:00
pub use crate::fn_native::{CallableFunction, FnCallArgs};
2020-09-30 17:27:41 +02:00
pub use crate::stdlib::{any::TypeId, boxed::Box, format, mem, string::ToString, vec as new_vec};
2021-03-03 15:49:29 +01:00
use crate::RhaiResult;
2020-11-16 16:10:14 +01:00
pub use crate::{
2020-11-17 05:23:53 +01:00
Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, Module,
2021-03-03 15:49:29 +01:00
NativeCallContext, Position, RegisterFn, RegisterResultFn,
2020-11-16 16:10:14 +01:00
};
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_.
2020-07-02 06:47:24 +02:00
///
2020-12-26 06:05:57 +01:00
/// This trait should not be used directly.
/// 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.
2021-03-02 08:02:28 +01:00
fn call(&self, context: NativeCallContext, args: &mut FnCallArgs) -> RhaiResult;
/// 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
2020-11-22 10:21:34 +01:00
/// Return a boxed slice of the names of the function's parameters.
fn input_names(&self) -> Box<[&'static str]>;
/// 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-11-22 15:15:17 +01:00
/// Return a string slice of the function's return type.
fn return_type(&self) -> &'static str;
2020-07-02 06:47:24 +02:00
}