2020-09-30 22:55:40 +08:00
|
|
|
//! Module defining macros for developing _plugins_.
|
2020-07-02 12:47:24 +08:00
|
|
|
|
2021-11-16 12:26:37 +08:00
|
|
|
pub use super::CallableFunction;
|
|
|
|
use super::FnCallArgs;
|
2020-11-16 23:10:14 +08:00
|
|
|
pub use crate::{
|
2020-11-17 12:23:53 +08:00
|
|
|
Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, Module,
|
2021-03-15 11:36:30 +08:00
|
|
|
NativeCallContext, Position,
|
2020-11-16 23:10:14 +08:00
|
|
|
};
|
2021-04-17 15:15:54 +08:00
|
|
|
#[cfg(feature = "no_std")]
|
|
|
|
use std::prelude::v1::*;
|
|
|
|
pub use std::{any::TypeId, mem};
|
2021-11-16 12:26:37 +08:00
|
|
|
|
2022-06-05 18:17:44 +08:00
|
|
|
/// Result of a Rhai function.
|
2021-12-25 23:49:14 +08:00
|
|
|
pub type RhaiResult = crate::RhaiResult;
|
2020-08-02 19:27:19 -05:00
|
|
|
|
2020-08-12 23:57:51 -05:00
|
|
|
#[cfg(not(features = "no_module"))]
|
2020-08-02 19:27:19 -05:00
|
|
|
pub use rhai_codegen::*;
|
2020-09-10 17:42:34 +08:00
|
|
|
#[cfg(features = "no_module")]
|
|
|
|
pub use rhai_codegen::{export_fn, register_exported_fn};
|
2020-07-02 12:47:24 +08:00
|
|
|
|
2020-09-30 22:55:40 +08:00
|
|
|
/// Trait implemented by a _plugin function_.
|
2020-07-02 12:47:24 +08:00
|
|
|
///
|
2020-12-26 13:05:57 +08:00
|
|
|
/// This trait should not be used directly.
|
2020-09-30 22:55:40 +08:00
|
|
|
/// Use the `#[export_module]` and `#[export_fn]` procedural attributes instead.
|
2020-07-02 12:47:24 +08:00
|
|
|
pub trait PluginFunction {
|
2020-09-30 22:55:40 +08:00
|
|
|
/// Call the plugin function with the arguments provided.
|
2021-03-02 15:02:28 +08:00
|
|
|
fn call(&self, context: NativeCallContext, args: &mut FnCallArgs) -> RhaiResult;
|
2020-09-30 22:55:40 +08:00
|
|
|
|
|
|
|
/// Is this plugin function a method?
|
2021-06-12 22:47:43 +08:00
|
|
|
#[must_use]
|
2020-07-02 12:47:24 +08:00
|
|
|
fn is_method_call(&self) -> bool;
|
2022-10-27 20:42:10 +08:00
|
|
|
|
|
|
|
/// Is this plugin function pure?
|
|
|
|
///
|
|
|
|
/// This defaults to `true` such that any old implementation that has constant-checking code
|
|
|
|
/// inside the function itself will continue to work.
|
|
|
|
#[inline(always)]
|
|
|
|
#[must_use]
|
|
|
|
fn is_pure(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
2020-07-02 12:47:24 +08:00
|
|
|
}
|