From bd8bf1945c37dfc2d56593a3aa183c5ba12a118e Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 12 May 2018 02:27:54 -0700 Subject: [PATCH] Super simple janky input --- schala-lang/src/eval.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 34763dc..812b5dc 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -1,5 +1,6 @@ use std::rc::Rc; use std::fmt::Write; +use std::io; use itertools::Itertools; @@ -21,6 +22,7 @@ impl<'a> State<'a> { let mut values = StateStack::new(Some(format!("global"))); builtin_binding!("print", values); builtin_binding!("println", values); + builtin_binding!("getline", values); State { values } } @@ -410,6 +412,11 @@ impl<'a> State<'a> { println!("{}", anything.to_repl()); Expr::Unit }, + ("getline", &[]) => { + let mut buf = String::new(); + io::stdin().read_line(&mut buf).expect("Error readling line in 'getline'"); + Lit(StringLit(Rc::new(buf))) + }, _ => return Err(format!("Runtime error: bad or unimplemented builtin")), }) }