Simplify code.

This commit is contained in:
Stephen Chung 2020-03-02 17:04:45 +08:00
parent 103c62fb43
commit cc87214750

View File

@ -71,15 +71,15 @@ impl Engine {
) -> Result<T, EvalAltResult> { ) -> Result<T, EvalAltResult> {
let AST(os, fns) = ast; let AST(os, fns) = ast;
for f in fns { fns.iter().for_each(|f| {
let spec = FnSpec { self.script_fns.insert(
ident: f.name.clone(), FnSpec {
args: None, ident: f.name.clone(),
}; args: None,
},
self.script_fns Arc::new(FnIntExt::Int(f.clone())),
.insert(spec, Arc::new(FnIntExt::Int(f.clone()))); );
} });
let result = os let result = os
.iter() .iter()
@ -133,17 +133,18 @@ impl Engine {
.map_err(|err| EvalAltResult::ErrorParsing(err)) .map_err(|err| EvalAltResult::ErrorParsing(err))
.and_then(|AST(ref os, ref fns)| { .and_then(|AST(ref os, ref fns)| {
for f in fns { for f in fns {
// FIX - Why are functions limited to 6 parameters?
if f.params.len() > 6 { if f.params.len() > 6 {
return Ok(()); return Ok(());
} }
let spec = FnSpec { self.script_fns.insert(
ident: f.name.clone(), FnSpec {
args: None, ident: f.name.clone(),
}; args: None,
},
self.script_fns Arc::new(FnIntExt::Int(f.clone())),
.insert(spec, Arc::new(FnIntExt::Int(f.clone()))); );
} }
let val = os let val = os