Refactoring a bit of the string/char parser code. Fmt'd
This commit is contained in:
parent
02e67963e7
commit
7a46c7d9bc
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rhai"
|
name = "rhai"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
authors = ["Jonathan Turner"]
|
authors = ["Jonathan Turner"]
|
||||||
description = "Embedded scripting for Rust"
|
description = "Embedded scripting for Rust"
|
||||||
homepage = "https://github.com/jonathandturner/rhai"
|
homepage = "https://github.com/jonathandturner/rhai"
|
||||||
|
934
src/engine.rs
934
src/engine.rs
File diff suppressed because it is too large
Load Diff
@ -8,16 +8,29 @@ pub trait FnRegister<A, RetVal, Args> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U, V, W, X, Y, Z> FnRegister<A, Z, (&'a mut T, U, V, W, X, Y)> for Engine
|
impl<'a, A, T, U, V, W, X, Y, Z> FnRegister<A, Z, (&'a mut T, U, V, W, X, Y)> for Engine
|
||||||
where A: 'static+Fn(&mut T, U, V, W, X, Y) -> Z, T: Any, U: Clone+Any, V: Clone+Any, W: Clone+Any,
|
where A: 'static + Fn(&mut T, U, V, W, X, Y) -> Z,
|
||||||
X: Clone+Any, Y: Clone+Any, Z: Any
|
T: Any,
|
||||||
|
U: Clone + Any,
|
||||||
|
V: Clone + Any,
|
||||||
|
W: Clone + Any,
|
||||||
|
X: Clone + Any,
|
||||||
|
Y: Clone + Any,
|
||||||
|
Z: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped : Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>,
|
let wrapped: Box<Fn(&mut Box<Any>,
|
||||||
&mut Box<Any>)->Result<Box<Any>, EvalAltResult>> =
|
&mut Box<Any>,
|
||||||
|
&mut Box<Any>,
|
||||||
Box::new(
|
&mut Box<Any>,
|
||||||
move |arg1: &mut Box<Any>, arg2: &mut Box<Any>, arg3: &mut Box<Any>, arg4: &mut Box<Any>,
|
&mut Box<Any>,
|
||||||
arg5: &mut Box<Any>, arg6: &mut Box<Any>| {
|
&mut Box<Any>)
|
||||||
|
-> Result<Box<Any>, EvalAltResult>> =
|
||||||
|
Box::new(move |arg1: &mut Box<Any>,
|
||||||
|
arg2: &mut Box<Any>,
|
||||||
|
arg3: &mut Box<Any>,
|
||||||
|
arg4: &mut Box<Any>,
|
||||||
|
arg5: &mut Box<Any>,
|
||||||
|
arg6: &mut Box<Any>| {
|
||||||
|
|
||||||
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
||||||
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
||||||
@ -27,12 +40,17 @@ impl<'a, A, T, U, V, W, X, Y, Z> FnRegister<A, Z, (&'a mut T, U, V, W, X, Y)> fo
|
|||||||
let inside6 = (*arg6).downcast_mut() as Option<&mut Y>;
|
let inside6 = (*arg6).downcast_mut() as Option<&mut Y>;
|
||||||
|
|
||||||
match (inside1, inside2, inside3, inside4, inside5, inside6) {
|
match (inside1, inside2, inside3, inside4, inside5, inside6) {
|
||||||
(Some(b), Some(c), Some(d), Some(e), Some(f), Some(g)) => Ok(Box::new(fun(b, c.clone(), d.clone(),
|
(Some(b), Some(c), Some(d), Some(e), Some(f), Some(g)) => {
|
||||||
e.clone(), f.clone(), g.clone())) as Box<Any>),
|
Ok(Box::new(fun(b,
|
||||||
_ => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
c.clone(),
|
||||||
|
d.clone(),
|
||||||
|
e.clone(),
|
||||||
|
f.clone(),
|
||||||
|
g.clone())) as Box<Any>)
|
||||||
}
|
}
|
||||||
|
_ => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn6(wrapped));
|
(*ent).push(FnType::ExternalFn6(wrapped));
|
||||||
@ -40,16 +58,29 @@ impl<'a, A, T, U, V, W, X, Y, Z> FnRegister<A, Z, (&'a mut T, U, V, W, X, Y)> fo
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U, V, W, X, Y, Z> FnRegister<A, Z, (&'a T, U, V, W, X, Y)> for Engine
|
impl<'a, A, T, U, V, W, X, Y, Z> FnRegister<A, Z, (&'a T, U, V, W, X, Y)> for Engine
|
||||||
where A: 'static+Fn(T, U, V, W, X, Y) -> Z, T: Clone+Any, U: Clone+Any, V: Clone+Any, W: Clone+Any,
|
where A: 'static + Fn(T, U, V, W, X, Y) -> Z,
|
||||||
X: Clone+Any, Y: Clone+Any, Z: Any
|
T: Clone + Any,
|
||||||
|
U: Clone + Any,
|
||||||
|
V: Clone + Any,
|
||||||
|
W: Clone + Any,
|
||||||
|
X: Clone + Any,
|
||||||
|
Y: Clone + Any,
|
||||||
|
Z: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped : Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>,
|
let wrapped: Box<Fn(&mut Box<Any>,
|
||||||
&mut Box<Any>)->Result<Box<Any>, EvalAltResult>> =
|
&mut Box<Any>,
|
||||||
|
&mut Box<Any>,
|
||||||
Box::new(
|
&mut Box<Any>,
|
||||||
move |arg1: &mut Box<Any>, arg2: &mut Box<Any>, arg3: &mut Box<Any>, arg4: &mut Box<Any>,
|
&mut Box<Any>,
|
||||||
arg5: &mut Box<Any>, arg6: &mut Box<Any>| {
|
&mut Box<Any>)
|
||||||
|
-> Result<Box<Any>, EvalAltResult>> =
|
||||||
|
Box::new(move |arg1: &mut Box<Any>,
|
||||||
|
arg2: &mut Box<Any>,
|
||||||
|
arg3: &mut Box<Any>,
|
||||||
|
arg4: &mut Box<Any>,
|
||||||
|
arg5: &mut Box<Any>,
|
||||||
|
arg6: &mut Box<Any>| {
|
||||||
|
|
||||||
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
||||||
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
||||||
@ -59,12 +90,17 @@ impl<'a, A, T, U, V, W, X, Y, Z> FnRegister<A, Z, (&'a T, U, V, W, X, Y)> for En
|
|||||||
let inside6 = (*arg6).downcast_mut() as Option<&mut Y>;
|
let inside6 = (*arg6).downcast_mut() as Option<&mut Y>;
|
||||||
|
|
||||||
match (inside1, inside2, inside3, inside4, inside5, inside6) {
|
match (inside1, inside2, inside3, inside4, inside5, inside6) {
|
||||||
(Some(b), Some(c), Some(d), Some(e), Some(f), Some(g)) => Ok(Box::new(fun(b.clone(), c.clone(), d.clone(),
|
(Some(b), Some(c), Some(d), Some(e), Some(f), Some(g)) => {
|
||||||
e.clone(), f.clone(), g.clone())) as Box<Any>),
|
Ok(Box::new(fun(b.clone(),
|
||||||
_ => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
c.clone(),
|
||||||
|
d.clone(),
|
||||||
|
e.clone(),
|
||||||
|
f.clone(),
|
||||||
|
g.clone())) as Box<Any>)
|
||||||
}
|
}
|
||||||
|
_ => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn6(wrapped));
|
(*ent).push(FnType::ExternalFn6(wrapped));
|
||||||
@ -72,12 +108,25 @@ impl<'a, A, T, U, V, W, X, Y, Z> FnRegister<A, Z, (&'a T, U, V, W, X, Y)> for En
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U, V, W, X, Y> FnRegister<A, Y, (&'a mut T, U, V, W, X)> for Engine
|
impl<'a, A, T, U, V, W, X, Y> FnRegister<A, Y, (&'a mut T, U, V, W, X)> for Engine
|
||||||
where A: 'static+Fn(&mut T, U, V, W, X) -> Y, T: Any, U: Clone+Any, V: Clone+Any, W: Clone+Any, X: Clone+Any, Y: Any
|
where A: 'static + Fn(&mut T, U, V, W, X) -> Y,
|
||||||
|
T: Any,
|
||||||
|
U: Clone + Any,
|
||||||
|
V: Clone + Any,
|
||||||
|
W: Clone + Any,
|
||||||
|
X: Clone + Any,
|
||||||
|
Y: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped : Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>)->Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn(&mut Box<Any>,
|
||||||
Box::new(
|
&mut Box<Any>,
|
||||||
move |arg1: &mut Box<Any>, arg2: &mut Box<Any>, arg3: &mut Box<Any>, arg4: &mut Box<Any>,
|
&mut Box<Any>,
|
||||||
|
&mut Box<Any>,
|
||||||
|
&mut Box<Any>)
|
||||||
|
-> Result<Box<Any>, EvalAltResult>> =
|
||||||
|
Box::new(move |arg1: &mut Box<Any>,
|
||||||
|
arg2: &mut Box<Any>,
|
||||||
|
arg3: &mut Box<Any>,
|
||||||
|
arg4: &mut Box<Any>,
|
||||||
arg5: &mut Box<Any>| {
|
arg5: &mut Box<Any>| {
|
||||||
|
|
||||||
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
||||||
@ -87,12 +136,12 @@ impl<'a, A, T, U, V, W, X, Y> FnRegister<A, Y, (&'a mut T, U, V, W, X)> for Engi
|
|||||||
let inside5 = (*arg5).downcast_mut() as Option<&mut X>;
|
let inside5 = (*arg5).downcast_mut() as Option<&mut X>;
|
||||||
|
|
||||||
match (inside1, inside2, inside3, inside4, inside5) {
|
match (inside1, inside2, inside3, inside4, inside5) {
|
||||||
(Some(b), Some(c), Some(d), Some(e), Some(f)) => Ok(Box::new(fun(b, c.clone(), d.clone(),
|
(Some(b), Some(c), Some(d), Some(e), Some(f)) => {
|
||||||
e.clone(), f.clone())) as Box<Any>),
|
Ok(Box::new(fun(b, c.clone(), d.clone(), e.clone(), f.clone())) as Box<Any>)
|
||||||
_ => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
|
||||||
}
|
}
|
||||||
|
_ => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn5(wrapped));
|
(*ent).push(FnType::ExternalFn5(wrapped));
|
||||||
@ -100,12 +149,25 @@ impl<'a, A, T, U, V, W, X, Y> FnRegister<A, Y, (&'a mut T, U, V, W, X)> for Engi
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U, V, W, X, Y> FnRegister<A, Y, (&'a T, U, V, W, X)> for Engine
|
impl<'a, A, T, U, V, W, X, Y> FnRegister<A, Y, (&'a T, U, V, W, X)> for Engine
|
||||||
where A: 'static+Fn(T, U, V, W, X) -> Y, T: Clone+Any, U: Clone+Any, V: Clone+Any, W: Clone+Any, X: Clone+Any, Y: Any
|
where A: 'static + Fn(T, U, V, W, X) -> Y,
|
||||||
|
T: Clone + Any,
|
||||||
|
U: Clone + Any,
|
||||||
|
V: Clone + Any,
|
||||||
|
W: Clone + Any,
|
||||||
|
X: Clone + Any,
|
||||||
|
Y: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped : Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>)->Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn(&mut Box<Any>,
|
||||||
Box::new(
|
&mut Box<Any>,
|
||||||
move |arg1: &mut Box<Any>, arg2: &mut Box<Any>, arg3: &mut Box<Any>, arg4: &mut Box<Any>,
|
&mut Box<Any>,
|
||||||
|
&mut Box<Any>,
|
||||||
|
&mut Box<Any>)
|
||||||
|
-> Result<Box<Any>, EvalAltResult>> =
|
||||||
|
Box::new(move |arg1: &mut Box<Any>,
|
||||||
|
arg2: &mut Box<Any>,
|
||||||
|
arg3: &mut Box<Any>,
|
||||||
|
arg4: &mut Box<Any>,
|
||||||
arg5: &mut Box<Any>| {
|
arg5: &mut Box<Any>| {
|
||||||
|
|
||||||
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
||||||
@ -115,12 +177,16 @@ impl<'a, A, T, U, V, W, X, Y> FnRegister<A, Y, (&'a T, U, V, W, X)> for Engine
|
|||||||
let inside5 = (*arg5).downcast_mut() as Option<&mut X>;
|
let inside5 = (*arg5).downcast_mut() as Option<&mut X>;
|
||||||
|
|
||||||
match (inside1, inside2, inside3, inside4, inside5) {
|
match (inside1, inside2, inside3, inside4, inside5) {
|
||||||
(Some(b), Some(c), Some(d), Some(e), Some(f)) => Ok(Box::new(fun(b.clone(), c.clone(), d.clone(),
|
(Some(b), Some(c), Some(d), Some(e), Some(f)) => {
|
||||||
e.clone(), f.clone())) as Box<Any>),
|
Ok(Box::new(fun(b.clone(),
|
||||||
_ => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
c.clone(),
|
||||||
|
d.clone(),
|
||||||
|
e.clone(),
|
||||||
|
f.clone())) as Box<Any>)
|
||||||
}
|
}
|
||||||
|
_ => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn5(wrapped));
|
(*ent).push(FnType::ExternalFn5(wrapped));
|
||||||
@ -128,23 +194,32 @@ impl<'a, A, T, U, V, W, X, Y> FnRegister<A, Y, (&'a T, U, V, W, X)> for Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U, V, W, X> FnRegister<A, X, (&'a mut T, U, V, W)> for Engine
|
impl<'a, A, T, U, V, W, X> FnRegister<A, X, (&'a mut T, U, V, W)> for Engine
|
||||||
where A: 'static+Fn(&mut T, U, V, W) -> X, T: Any, U: Clone+Any, V: Clone+Any, W: Clone+Any, X: Any
|
where A: 'static + Fn(&mut T, U, V, W) -> X,
|
||||||
|
T: Any,
|
||||||
|
U: Clone + Any,
|
||||||
|
V: Clone + Any,
|
||||||
|
W: Clone + Any,
|
||||||
|
X: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped : Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>)->Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>)
|
||||||
Box::new(
|
-> Result<Box<Any>, EvalAltResult>> =
|
||||||
move |arg1: &mut Box<Any>, arg2: &mut Box<Any>, arg3: &mut Box<Any>, arg4: &mut Box<Any>| {
|
Box::new(move |arg1: &mut Box<Any>,
|
||||||
|
arg2: &mut Box<Any>,
|
||||||
|
arg3: &mut Box<Any>,
|
||||||
|
arg4: &mut Box<Any>| {
|
||||||
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
||||||
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
||||||
let inside3 = (*arg3).downcast_mut() as Option<&mut V>;
|
let inside3 = (*arg3).downcast_mut() as Option<&mut V>;
|
||||||
let inside4 = (*arg4).downcast_mut() as Option<&mut W>;
|
let inside4 = (*arg4).downcast_mut() as Option<&mut W>;
|
||||||
|
|
||||||
match (inside1, inside2, inside3, inside4) {
|
match (inside1, inside2, inside3, inside4) {
|
||||||
(Some(b), Some(c), Some(d), Some(e)) => Ok(Box::new(fun(b, c.clone(), d.clone(), e.clone())) as Box<Any>),
|
(Some(b), Some(c), Some(d), Some(e)) => {
|
||||||
_ => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
Ok(Box::new(fun(b, c.clone(), d.clone(), e.clone())) as Box<Any>)
|
||||||
}
|
}
|
||||||
|
_ => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn4(wrapped));
|
(*ent).push(FnType::ExternalFn4(wrapped));
|
||||||
@ -152,23 +227,32 @@ impl<'a, A, T, U, V, W, X> FnRegister<A, X, (&'a mut T, U, V, W)> for Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U, V, W, X> FnRegister<A, X, (&'a T, U, V, W)> for Engine
|
impl<'a, A, T, U, V, W, X> FnRegister<A, X, (&'a T, U, V, W)> for Engine
|
||||||
where A: 'static+Fn(T, U, V, W) -> X, T: Clone+Any, U: Clone+Any, V: Clone+Any, W: Clone+Any, X: Any
|
where A: 'static + Fn(T, U, V, W) -> X,
|
||||||
|
T: Clone + Any,
|
||||||
|
U: Clone + Any,
|
||||||
|
V: Clone + Any,
|
||||||
|
W: Clone + Any,
|
||||||
|
X: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped : Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>)->Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>, &mut Box<Any>)
|
||||||
Box::new(
|
-> Result<Box<Any>, EvalAltResult>> =
|
||||||
move |arg1: &mut Box<Any>, arg2: &mut Box<Any>, arg3: &mut Box<Any>, arg4: &mut Box<Any>| {
|
Box::new(move |arg1: &mut Box<Any>,
|
||||||
|
arg2: &mut Box<Any>,
|
||||||
|
arg3: &mut Box<Any>,
|
||||||
|
arg4: &mut Box<Any>| {
|
||||||
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
||||||
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
||||||
let inside3 = (*arg3).downcast_mut() as Option<&mut V>;
|
let inside3 = (*arg3).downcast_mut() as Option<&mut V>;
|
||||||
let inside4 = (*arg4).downcast_mut() as Option<&mut W>;
|
let inside4 = (*arg4).downcast_mut() as Option<&mut W>;
|
||||||
|
|
||||||
match (inside1, inside2, inside3, inside4) {
|
match (inside1, inside2, inside3, inside4) {
|
||||||
(Some(b), Some(c), Some(d), Some(e)) => Ok(Box::new(fun(b.clone(), c.clone(), d.clone(), e.clone())) as Box<Any>),
|
(Some(b), Some(c), Some(d), Some(e)) => {
|
||||||
_ => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
Ok(Box::new(fun(b.clone(), c.clone(), d.clone(), e.clone())) as Box<Any>)
|
||||||
}
|
}
|
||||||
|
_ => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn4(wrapped));
|
(*ent).push(FnType::ExternalFn4(wrapped));
|
||||||
@ -176,22 +260,27 @@ impl<'a, A, T, U, V, W, X> FnRegister<A, X, (&'a T, U, V, W)> for Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U, V, W> FnRegister<A, W, (&'a mut T, U, V)> for Engine
|
impl<'a, A, T, U, V, W> FnRegister<A, W, (&'a mut T, U, V)> for Engine
|
||||||
where A: 'static+Fn(&mut T, U, V) -> W, T: Any, U: Clone+Any, V: Clone+Any, W: Any
|
where A: 'static + Fn(&mut T, U, V) -> W,
|
||||||
|
T: Any,
|
||||||
|
U: Clone + Any,
|
||||||
|
V: Clone + Any,
|
||||||
|
W: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped : Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>)->Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>)
|
||||||
Box::new(
|
-> Result<Box<Any>, EvalAltResult>> =
|
||||||
move |arg1: &mut Box<Any>, arg2: &mut Box<Any>, arg3: &mut Box<Any>| {
|
Box::new(move |arg1: &mut Box<Any>, arg2: &mut Box<Any>, arg3: &mut Box<Any>| {
|
||||||
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
||||||
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
||||||
let inside3 = (*arg3).downcast_mut() as Option<&mut V>;
|
let inside3 = (*arg3).downcast_mut() as Option<&mut V>;
|
||||||
|
|
||||||
match (inside1, inside2, inside3) {
|
match (inside1, inside2, inside3) {
|
||||||
(Some(b), Some(c), Some(d)) => Ok(Box::new(fun(b, c.clone(), d.clone())) as Box<Any>),
|
(Some(b), Some(c), Some(d)) => {
|
||||||
_ => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
Ok(Box::new(fun(b, c.clone(), d.clone())) as Box<Any>)
|
||||||
}
|
}
|
||||||
|
_ => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn3(wrapped));
|
(*ent).push(FnType::ExternalFn3(wrapped));
|
||||||
@ -199,22 +288,27 @@ impl<'a, A, T, U, V, W> FnRegister<A, W, (&'a mut T, U, V)> for Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U, V, W> FnRegister<A, W, (&'a T, U, V)> for Engine
|
impl<'a, A, T, U, V, W> FnRegister<A, W, (&'a T, U, V)> for Engine
|
||||||
where A: 'static+Fn(T, U, V) -> W, T: Clone+Any, U: Clone+Any, V: Clone+Any, W: Any
|
where A: 'static + Fn(T, U, V) -> W,
|
||||||
|
T: Clone + Any,
|
||||||
|
U: Clone + Any,
|
||||||
|
V: Clone + Any,
|
||||||
|
W: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped : Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>)->Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn(&mut Box<Any>, &mut Box<Any>, &mut Box<Any>)
|
||||||
Box::new(
|
-> Result<Box<Any>, EvalAltResult>> =
|
||||||
move |arg1: &mut Box<Any>, arg2: &mut Box<Any>, arg3: &mut Box<Any>| {
|
Box::new(move |arg1: &mut Box<Any>, arg2: &mut Box<Any>, arg3: &mut Box<Any>| {
|
||||||
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
||||||
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
||||||
let inside3 = (*arg3).downcast_mut() as Option<&mut V>;
|
let inside3 = (*arg3).downcast_mut() as Option<&mut V>;
|
||||||
|
|
||||||
match (inside1, inside2, inside3) {
|
match (inside1, inside2, inside3) {
|
||||||
(Some(b), Some(c), Some(d)) => Ok(Box::new(fun(b.clone(), c.clone(), d.clone())) as Box<Any>),
|
(Some(b), Some(c), Some(d)) => {
|
||||||
_ => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
Ok(Box::new(fun(b.clone(), c.clone(), d.clone())) as Box<Any>)
|
||||||
}
|
}
|
||||||
|
_ => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn3(wrapped));
|
(*ent).push(FnType::ExternalFn3(wrapped));
|
||||||
@ -222,21 +316,22 @@ impl<'a, A, T, U, V, W> FnRegister<A, W, (&'a T, U, V)> for Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U, V> FnRegister<A, V, (&'a mut T, U)> for Engine
|
impl<'a, A, T, U, V> FnRegister<A, V, (&'a mut T, U)> for Engine
|
||||||
where A: 'static+Fn(&mut T, U) -> V, T: Any, U: Clone+Any, V: Any
|
where A: 'static + Fn(&mut T, U) -> V,
|
||||||
|
T: Any,
|
||||||
|
U: Clone + Any,
|
||||||
|
V: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped: Box<Fn(&mut Box<Any>, &mut Box<Any>) -> Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn(&mut Box<Any>, &mut Box<Any>) -> Result<Box<Any>, EvalAltResult>> =
|
||||||
Box::new(
|
Box::new(move |arg1: &mut Box<Any>, arg2: &mut Box<Any>| {
|
||||||
move |arg1: &mut Box<Any>, arg2: &mut Box<Any>| {
|
|
||||||
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
||||||
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
||||||
|
|
||||||
match (inside1, inside2) {
|
match (inside1, inside2) {
|
||||||
(Some(b), Some(c)) => Ok(Box::new(fun(b, c.clone())) as Box<Any>),
|
(Some(b), Some(c)) => Ok(Box::new(fun(b, c.clone())) as Box<Any>),
|
||||||
_ => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
_ => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn2(wrapped));
|
(*ent).push(FnType::ExternalFn2(wrapped));
|
||||||
@ -244,21 +339,22 @@ impl<'a, A, T, U, V> FnRegister<A, V, (&'a mut T, U)> for Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U, V> FnRegister<A, V, (&'a T, U)> for Engine
|
impl<'a, A, T, U, V> FnRegister<A, V, (&'a T, U)> for Engine
|
||||||
where A: 'static+Fn(T, U) -> V, T: Clone+Any, U: Clone+Any, V: Any
|
where A: 'static + Fn(T, U) -> V,
|
||||||
|
T: Clone + Any,
|
||||||
|
U: Clone + Any,
|
||||||
|
V: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped: Box<Fn(&mut Box<Any>, &mut Box<Any>) -> Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn(&mut Box<Any>, &mut Box<Any>) -> Result<Box<Any>, EvalAltResult>> =
|
||||||
Box::new(
|
Box::new(move |arg1: &mut Box<Any>, arg2: &mut Box<Any>| {
|
||||||
move |arg1: &mut Box<Any>, arg2: &mut Box<Any>| {
|
|
||||||
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
let inside1 = (*arg1).downcast_mut() as Option<&mut T>;
|
||||||
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
let inside2 = (*arg2).downcast_mut() as Option<&mut U>;
|
||||||
|
|
||||||
match (inside1, inside2) {
|
match (inside1, inside2) {
|
||||||
(Some(b), Some(c)) => Ok(Box::new(fun(b.clone(), c.clone())) as Box<Any>),
|
(Some(b), Some(c)) => Ok(Box::new(fun(b.clone(), c.clone())) as Box<Any>),
|
||||||
_ => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
_ => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn2(wrapped));
|
(*ent).push(FnType::ExternalFn2(wrapped));
|
||||||
@ -266,20 +362,20 @@ impl<'a, A, T, U, V> FnRegister<A, V, (&'a T, U)> for Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A, T, U> FnRegister<A, U, (&'a mut T)> for Engine
|
impl<'a, A, T, U> FnRegister<A, U, (&'a mut T)> for Engine
|
||||||
where A: 'static+Fn(&mut T) -> U, T: Any, U: Any
|
where A: 'static + Fn(&mut T) -> U,
|
||||||
|
T: Any,
|
||||||
|
U: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped: Box<Fn(&mut Box<Any>) -> Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn(&mut Box<Any>) -> Result<Box<Any>, EvalAltResult>> =
|
||||||
Box::new(
|
Box::new(move |arg: &mut Box<Any>| {
|
||||||
move |arg: &mut Box<Any>| {
|
|
||||||
let inside = (*arg).downcast_mut() as Option<&mut T>;
|
let inside = (*arg).downcast_mut() as Option<&mut T>;
|
||||||
|
|
||||||
match inside {
|
match inside {
|
||||||
Some(b) => Ok(Box::new(fun(b)) as Box<Any>),
|
Some(b) => Ok(Box::new(fun(b)) as Box<Any>),
|
||||||
None => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
None => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn1(wrapped));
|
(*ent).push(FnType::ExternalFn1(wrapped));
|
||||||
@ -288,19 +384,19 @@ impl<'a, A, T, U> FnRegister<A, U, (&'a mut T)> for Engine
|
|||||||
|
|
||||||
|
|
||||||
impl<'a, A, T, U> FnRegister<A, U, (&'a T)> for Engine
|
impl<'a, A, T, U> FnRegister<A, U, (&'a T)> for Engine
|
||||||
where A: 'static+Fn(T) -> U, T: Clone+Any, U: Any
|
where A: 'static + Fn(T) -> U,
|
||||||
|
T: Clone + Any,
|
||||||
|
U: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped: Box<Fn(&mut Box<Any>) -> Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn(&mut Box<Any>) -> Result<Box<Any>, EvalAltResult>> =
|
||||||
Box::new(
|
Box::new(move |arg: &mut Box<Any>| {
|
||||||
move |arg: &mut Box<Any>| {
|
|
||||||
let inside = (*arg).downcast_mut() as Option<&mut T>;
|
let inside = (*arg).downcast_mut() as Option<&mut T>;
|
||||||
match inside {
|
match inside {
|
||||||
Some(b) => Ok(Box::new(fun(b.clone())) as Box<Any>),
|
Some(b) => Ok(Box::new(fun(b.clone())) as Box<Any>),
|
||||||
None => Err(EvalAltResult::ErrorFunctionArgMismatch)
|
None => Err(EvalAltResult::ErrorFunctionArgMismatch),
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn1(wrapped));
|
(*ent).push(FnType::ExternalFn1(wrapped));
|
||||||
@ -308,13 +404,13 @@ impl<'a, A, T, U> FnRegister<A, U, (&'a T)> for Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<A, T> FnRegister<A, T, ()> for Engine
|
impl<A, T> FnRegister<A, T, ()> for Engine
|
||||||
where A: 'static+Fn() -> T, T: Any
|
where A: 'static + Fn() -> T,
|
||||||
|
T: Any
|
||||||
{
|
{
|
||||||
fn register_fn(&mut self, name: &str, fun: A) {
|
fn register_fn(&mut self, name: &str, fun: A) {
|
||||||
let wrapped : Box<Fn()->Result<Box<Any>, EvalAltResult>> =
|
let wrapped: Box<Fn() -> Result<Box<Any>, EvalAltResult>> = Box::new(move || {
|
||||||
Box::new(
|
Ok(Box::new(fun()) as Box<Any>)
|
||||||
move || { Ok(Box::new(fun()) as Box<Any>) }
|
});
|
||||||
);
|
|
||||||
|
|
||||||
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
let ent = self.fns.entry(name.to_string()).or_insert(Vec::new());
|
||||||
(*ent).push(FnType::ExternalFn0(wrapped));
|
(*ent).push(FnType::ExternalFn0(wrapped));
|
||||||
|
758
src/parser.rs
758
src/parser.rs
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user