summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-01-09 20:22:51 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-01-09 20:22:51 -0500
commit39b49c97421578332832832f3ca4a18c9816cefb (patch)
tree86eefa091bfb86bfb2f7996cd12ec6a9c6596c63 /2d
parent38c45af24c23d039af07a113725210072293754d (diff)
Run REPL even when game is paused.
* 2d/repl/repl.scm (add-to-repl-mvar): New procedure. (poll-interval): New variable. (flush-repl): Schedule in paused-agenda.
Diffstat (limited to '2d')
-rw-r--r--2d/repl/repl.scm37
1 files changed, 20 insertions, 17 deletions
diff --git a/2d/repl/repl.scm b/2d/repl/repl.scm
index 6b0a69b..dbdabd3 100644
--- a/2d/repl/repl.scm
+++ b/2d/repl/repl.scm
@@ -152,13 +152,26 @@ INPUT, OUTPUT, and ERROR ports."
(with-fluids ((*repl-stack* stack))
(thunk))))))))))
+(define (add-to-repl-mvar thunk-ports-and-stack)
+ ;; Insert thunk into repl-mvar. The game loop will schedule it and
+ ;; run it on the next tick. We also pass along the
+ ;; input/output/error ports and the REPL stack.
+ (put-mvar repl-input-mvar thunk-ports-and-stack)
+ ;; Read the results back from game-mvar. Will block until results
+ ;; are available.
+ (take-mvar repl-output-mvar))
+
(define (flush-repl)
"Execute a thunk from the REPL is there is one."
(unless (mvar-empty? repl-input-mvar)
(and-let* ((vals (try-take-mvar repl-input-mvar)))
(apply run-repl-thunk vals))))
-(schedule-interval flush-repl 5)
+(define poll-interval 5)
+
+(schedule-interval flush-repl poll-interval)
+(with-agenda paused-agenda
+ (schedule-interval flush-repl poll-interval))
;;;
;;; The repl
@@ -224,27 +237,17 @@ INPUT, OUTPUT, and ERROR ports."
(abort-on-error "parsing expression"
(repl-parse repl exp))))))
(run-hook before-eval-hook exp)
- ;; Insert thunk into repl-mvar. The
- ;; game loop will schedule it and run
- ;; it on the next tick. We also pass
- ;; along the input/output/error ports
- ;; and the REPL stack.
- (put-mvar
- repl-input-mvar
+ (add-to-repl-mvar
(list
(lambda ()
- (call-with-error-handling
- (lambda ()
- (with-stack-and-prompt thunk))
- #:on-error (repl-option-ref repl 'on-error)))
+ (call-with-error-handling
+ (lambda ()
+ (with-stack-and-prompt thunk))
+ #:on-error (repl-option-ref repl 'on-error)))
(current-input-port)
(current-output-port)
(current-error-port)
- (fluid-ref *repl-stack*)))
- ;; Read the results back from
- ;; game-mvar. Will block until results
- ;; are available.
- (take-mvar repl-output-mvar))
+ (fluid-ref *repl-stack*))))
(lambda (k) (values))))
(lambda l
(for-each (lambda (v)