From bbfca639547fcd08e51181b70e449e71281d1d9b Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 28 Mar 2021 09:51:26 +0530 Subject: add new brush type --- src/lisp/prelude.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/lisp/prelude.rs') diff --git a/src/lisp/prelude.rs b/src/lisp/prelude.rs index 6153e4f..d2a6ae6 100644 --- a/src/lisp/prelude.rs +++ b/src/lisp/prelude.rs @@ -1,7 +1,8 @@ use crate::{ + brush::Brush, lisp::{ error::{EvalError, LispError}, - expr::{Arity, LispExpr}, + expr::{is_ident, Arity, LispExpr}, number::LispNumber, Environment, }, @@ -193,5 +194,23 @@ pub fn new_env() -> Environment { return Ok(LispExpr::Unit); }); + primitive!(env, Arity::Atmost(1), "brush", |args, app| { + info!("brush {}", &args[0]); + if let [LispExpr::Quote(kind, _)] = args { + if is_ident(kind) { + match (&**kind).as_ref() { + "fill" => app.brush = Brush::Fill, + "circle" => app.brush = Brush::new(), + "line" => app.brush = Brush::line(0, false), + "line-extend" => app.brush = Brush::line(0, true), + _ => return Err(EvalError::CustomInternal("unknown brush type").into()), + } + } + } else { + return Err(EvalError::TypeMismatch.into()); + } + return Ok(LispExpr::Unit); + }); + env } -- cgit v1.2.3