From 1bc69dceb044af644103aa29e5fa2249655a75a6 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 14 Oct 2017 13:48:18 -0400 Subject: 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. --- chickadee/scripting.scm | 6 +++++- chickadee/scripting/coroutine.scm | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'chickadee') 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)) -- cgit v1.2.3