New Procedural Macros Crate v0.1
This commit is contained in:
@@ -681,6 +681,13 @@ impl Dynamic {
|
||||
}
|
||||
}
|
||||
|
||||
/// Copy and return a `Dynamic` if it contains a type that can be trivially copied.
|
||||
/// Returns `None` if the cast fails.
|
||||
#[inline(always)]
|
||||
pub fn downcast_clone<T: Variant + Clone>(&self) -> Option<T> {
|
||||
self.downcast_ref::<T>().map(|t| t.clone())
|
||||
}
|
||||
|
||||
/// Cast the `Dynamic` as the system integer type `INT` and return it.
|
||||
/// Returns the name of the actual type if the cast fails.
|
||||
pub fn as_int(&self) -> Result<INT, &'static str> {
|
||||
|
@@ -43,7 +43,7 @@ pub trait RegisterPlugin<PL: crate::plugin::Plugin> {
|
||||
/// fn is_method_call(&self) -> bool { false }
|
||||
/// fn is_varadic(&self) -> bool { false }
|
||||
///
|
||||
/// fn call(&self, args: &[&mut Dynamic], pos: Position) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
/// fn call(&self, args: &mut[&mut Dynamic], pos: Position) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
/// let x1: &FLOAT = args[0].downcast_ref::<FLOAT>().unwrap();
|
||||
/// let y1: &FLOAT = args[1].downcast_ref::<FLOAT>().unwrap();
|
||||
/// let x2: &FLOAT = args[2].downcast_ref::<FLOAT>().unwrap();
|
||||
@@ -55,6 +55,13 @@ pub trait RegisterPlugin<PL: crate::plugin::Plugin> {
|
||||
/// fn clone_boxed(&self) -> Box<dyn PluginFunction> {
|
||||
/// Box::new(DistanceFunction())
|
||||
/// }
|
||||
///
|
||||
/// fn input_types(&self) -> Box<[std::any::TypeId]> {
|
||||
/// vec![std::any::TypeId::of::<FLOAT>(),
|
||||
/// std::any::TypeId::of::<FLOAT>(),
|
||||
/// std::any::TypeId::of::<FLOAT>(),
|
||||
/// std::any::TypeId::of::<FLOAT>()].into_boxed_slice()
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// // A simple custom plugin. This should not usually be done with hand-written code.
|
||||
|
@@ -98,6 +98,8 @@ pub use syntax::{EvalContext, Expression};
|
||||
pub use token::Position;
|
||||
pub use utils::calc_fn_spec as calc_fn_hash;
|
||||
|
||||
pub use rhai_codegen::*;
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub use parser::FnAccess;
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
//! Module defining plugins in Rhai. Is exported for use by plugin authors.
|
||||
|
||||
use crate::stdlib::boxed::Box;
|
||||
use crate::stdlib::{any::TypeId, boxed::Box};
|
||||
|
||||
pub use crate::any::{Dynamic, Variant};
|
||||
pub use crate::fn_native::{CallableFunction, FnCallArgs, IteratorFn};
|
||||
@@ -38,7 +38,9 @@ pub trait PluginFunction {
|
||||
fn is_method_call(&self) -> bool;
|
||||
fn is_varadic(&self) -> bool;
|
||||
|
||||
fn call(&self, args: &[&mut Dynamic], pos: Position) -> Result<Dynamic, Box<EvalAltResult>>;
|
||||
fn call(&self, args: &mut[&mut Dynamic], pos: Position) -> Result<Dynamic, Box<EvalAltResult>>;
|
||||
|
||||
fn clone_boxed(&self) -> Box<dyn PluginFunction>;
|
||||
|
||||
fn input_types(&self) -> Box<[TypeId]>;
|
||||
}
|
||||
|
Reference in New Issue
Block a user