summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2017-10-14 13:48:18 -0400
committerDavid Thompson <dthompson2@worcester.edu>2017-10-14 13:48:18 -0400
commit1bc69dceb044af644103aa29e5fa2249655a75a6 (patch)
treebdd4b8bc1e4becfbfd9ed79614d14a5740cd5fba
parent968c8e6876a7dcd036e75cc92a33b2ac67930ddb (diff)
scripting: Fix bug where dynamic state wasn't being respected.
* chickadee/scripting/coroutine.scm (spawn-coroutine): Save dynamic state during coroutine execution. * chickadee/scripting.scm (wait): Schedule continuation in the coroutine's current agenda.
-rw-r--r--chickadee/scripting.scm6
-rw-r--r--chickadee/scripting/coroutine.scm8
2 files changed, 10 insertions, 4 deletions
diff --git a/chickadee/scripting.scm b/chickadee/scripting.scm
index 5d24ce9..d4a2b81 100644
--- a/chickadee/scripting.scm
+++ b/chickadee/scripting.scm
@@ -42,7 +42,11 @@
(define (wait duration)
"Wait DURATION before resuming the current coroutine."
- (yield (lambda (cont) (schedule-after duration cont))))
+ (let ((agenda (current-agenda)))
+ (yield
+ (lambda (cont)
+ (with-agenda agenda
+ (schedule-after duration cont))))))
(define* (tween duration start end proc #:key
(step 1)
diff --git a/chickadee/scripting/coroutine.scm b/chickadee/scripting/coroutine.scm
index 38f0da0..642ff83 100644
--- a/chickadee/scripting/coroutine.scm
+++ b/chickadee/scripting/coroutine.scm
@@ -71,9 +71,11 @@
handler)))
(when (procedure? callback)
(apply callback resume args)))
- (define (task)
- (thunk)
- (set-coroutine-status! co 'complete))
+ (define task
+ (let ((dynamic-state (current-dynamic-state)))
+ (lambda ()
+ (with-dynamic-state dynamic-state thunk)
+ (set-coroutine-status! co 'complete))))
;; Start the coroutine.
(call-with-prompt coroutine-prompt task handler)
co))