about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-10 11:49:27 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-10 11:49:27 -0700
commita66ad5339e35b2ada7f749103025c6800bd78796 (patch)
tree696d6ff78e3715307b978d5d05a99aef164ac03c
parent971e710df91130740a28dc7067e53ecf61ef24bd (diff)
downloadmu-a66ad5339e35b2ada7f749103025c6800bd78796.tar.gz
1329
-rw-r--r--061channel.mu11
-rw-r--r--chessboard.mu1
2 files changed, 12 insertions, 0 deletions
diff --git a/061channel.mu b/061channel.mu
index 79f4dd02..99ca660f 100644
--- a/061channel.mu
+++ b/061channel.mu
@@ -106,6 +106,17 @@ recipe read [
   reply result:location, chan:address:channel/same-as-ingredient:0
 ]
 
+recipe clear-channel [
+  default-space:address:address:array:location <- new location:type, 30:literal
+  chan:address:channel <- next-ingredient
+  {
+    empty?:boolean <- channel-empty? chan:address:channel
+    break-if empty?:boolean
+    _, chan:address:channel <- read chan:address:channel
+  }
+  reply chan:address:channel/same-as-ingredient:0
+]
+
 scenario channel-initialization [
   run [
     1:address:channel <- init-channel 3:literal/capacity
diff --git a/chessboard.mu b/chessboard.mu
index 11d2c9d3..bf873760 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -589,6 +589,7 @@ recipe chessboard [
       print-string 0:literal/screen, msg:address:array:character
       m:address:move, quit:boolean, error:boolean <- read-move buffered-stdin:address:channel, 0:literal/screen
       break-if quit:boolean, +quit:offset
+      buffered-stdin:address:channel <- clear-channel buffered-stdin:address:channel  # cleanup after error. todo: test this?
       loop-if error:boolean
     }
     board:address:array:address:array:character <- make-move board:address:array:address:array:character, m:address:move