From 0ac507e3b355de4d804d7f308a44cf7a345f9705 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 13 Feb 2022 00:25:56 +0100 Subject: [PATCH] implemented subtraction for built-in functios --- ablescript/src/variables.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 66c3ffcf..dbe6c285 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -635,7 +635,27 @@ impl ops::Sub for Value { ) .into_functio(), }, - Functio::Builtin(_) => todo!(), + Functio::Builtin(b) => { + let arity = b.arity; + let resulting_arity = arity.saturating_sub(rhs.into_i32() as usize); + + Functio::Builtin(BuiltinFunctio::new( + move |args| { + b.call( + &args + .iter() + .cloned() + .take(resulting_arity) + .chain(std::iter::repeat_with(|| { + Rc::new(RefCell::new(Value::Nul)) + })) + .take(arity) + .collect::>(), + ) + }, + resulting_arity, + )) + } Functio::Chain { functios, .. } => { let rhs = rhs.into_functio(); let (a, b) = *functios;