aboutsummaryrefslogtreecommitdiff
path: root/src/lisp/prelude.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lisp/prelude.rs')
-rw-r--r--src/lisp/prelude.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/lisp/prelude.rs b/src/lisp/prelude.rs
index 7cb46ff..8088510 100644
--- a/src/lisp/prelude.rs
+++ b/src/lisp/prelude.rs
@@ -14,7 +14,7 @@ use crate::{
14 utils::{load_script, rect_coords}, 14 utils::{load_script, rect_coords},
15}; 15};
16 16
17use std::convert::TryInto; 17use std::{convert::TryInto, fs::File, io::BufWriter, path::Path};
18 18
19#[macro_export] 19#[macro_export]
20macro_rules! primitive { 20macro_rules! primitive {
@@ -260,6 +260,18 @@ pub fn new_env() -> Result<Environment, LispError> {
260 } 260 }
261 }); 261 });
262 262
263 primitive!(env, Arity::Exact(1), "export-png", |args, app| {
264 if let LispExpr::StringLit(s) = &args[0] {
265 let export_path = Path::new(&s);
266 let file = File::create(export_path).map_err(EvalError::FileError)?;
267 let w = BufWriter::new(file);
268 app.export().write_png(w);
269 Ok(LispExpr::Unit)
270 } else {
271 Err(EvalError::TypeMismatch.into())
272 }
273 });
274
263 primitive!(env, Arity::Exact(0), "grid-enabled?", |_, app| { 275 primitive!(env, Arity::Exact(0), "grid-enabled?", |_, app| {
264 Ok(LispExpr::BoolLit(app.grid.enabled)) 276 Ok(LispExpr::BoolLit(app.grid.enabled))
265 }); 277 });
@@ -524,5 +536,6 @@ pub fn new_env() -> Result<Environment, LispError> {
524 primitive!(env, Arity::Exact(1), "id", |args, _| { 536 primitive!(env, Arity::Exact(1), "id", |args, _| {
525 Ok(args[0].clone()) 537 Ok(args[0].clone())
526 }); 538 });
539
527 Ok(env) 540 Ok(env)
528} 541}