2020-09-30 16:55:40 +02:00
|
|
|
//! Module defining macros for developing _plugins_.
|
2020-07-02 06:47:24 +02:00
|
|
|
|
2021-11-16 05:26:37 +01:00
|
|
|
pub use super::CallableFunction;
|
|
|
|
use super::FnCallArgs;
|
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-15 04:36:30 +01:00
|
|
|
NativeCallContext, Position,
|
2020-11-16 16:10:14 +01:00
|
|
|
};
|
2021-04-17 09:15:54 +02:00
|
|
|
#[cfg(feature = "no_std")]
|
|
|
|
use std::prelude::v1::*;
|
|
|
|
pub use std::{any::TypeId, mem};
|
2021-11-16 05:26:37 +01:00
|
|
|
|
2022-06-05 12:17:44 +02:00
|
|
|
/// Result of a Rhai function.
|
2021-12-25 16:49:14 +01:00
|
|
|
pub type RhaiResult = crate::RhaiResult;
|
2020-08-03 02:27:19 +02:00
|
|
|
|
2020-08-13 06:57:51 +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
|
|
|
|
2020-09-30 16:55:40 +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.
|
2020-09-30 16:55:40 +02:00
|
|
|
/// Use the `#[export_module]` and `#[export_fn]` procedural attributes instead.
|
2020-07-02 06:47:24 +02:00
|
|
|
pub trait PluginFunction {
|
2020-09-30 16:55:40 +02:00
|
|
|
/// 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;
|
2020-09-30 16:55:40 +02:00
|
|
|
|
|
|
|
/// Is this plugin function a method?
|
2021-06-12 16:47:43 +02:00
|
|
|
#[must_use]
|
2020-07-02 06:47:24 +02:00
|
|
|
fn is_method_call(&self) -> bool;
|
2022-10-27 14:42:10 +02: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 06:47:24 +02:00
|
|
|
}
|