summaryrefslogtreecommitdiff
path: root/2d/repl
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-09-02 16:52:53 -0400
committerDavid Thompson <dthompson@member.fsf.org>2013-09-02 16:52:53 -0400
commit2d67cf8ec58c87609c242a7b93a2c1470c8d6180 (patch)
tree731d8b10bffedda0461ba4fb5bdddc6ea8ca726f /2d/repl
parent25e559518f9087b0891dbf8500a217d71f0f15d8 (diff)
Execute REPL thunks in the context of the main game thread.
Diffstat (limited to '2d/repl')
-rw-r--r--2d/repl/repl.scm28
1 files changed, 23 insertions, 5 deletions
diff --git a/2d/repl/repl.scm b/2d/repl/repl.scm
index 433e0e7..a5b0536 100644
--- a/2d/repl/repl.scm
+++ b/2d/repl/repl.scm
@@ -29,7 +29,9 @@
#:use-module (system repl common)
#:use-module (system repl command)
#:use-module (ice-9 control)
- #:export (start-repl run-repl))
+ #:use-module (2d mvars)
+ #:use-module (2d game-loop)
+ #:export (repl-mvar start-repl run-repl))
;;;
@@ -128,6 +130,8 @@
;;; The repl
;;;
+(define repl-mvar (new-mvar))
+
(define* (start-repl #:optional (lang (current-language)) #:key debug)
;; ,language at the REPL will update the current-language. Make
;; sure that it does so in a new dynamic scope.
@@ -188,10 +192,24 @@
(abort-on-error "parsing expression"
(repl-parse repl exp))))))
(run-hook before-eval-hook exp)
- (call-with-error-handling
- (lambda ()
- (with-stack-and-prompt thunk))
- #:on-error (repl-option-ref repl 'on-error)))
+ ;; Insert thunk into repl-mvar. The
+ ;; game loop will schedule it and run
+ ;; it on the next tick.
+ (put-mvar
+ repl-mvar
+ (list
+ (lambda ()
+ (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)))
+ ;; Read the results back from
+ ;; game-mvar. Will block until results
+ ;; are available.
+ (take-mvar game-mvar))
(lambda (k) (values))))
(lambda l
(for-each (lambda (v)