[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Interactive programming with Event Loop?
From: |
Thompson, David |
Subject: |
Re: Interactive programming with Event Loop? |
Date: |
Fri, 6 Oct 2017 09:01:29 -0400 |
Hello Christopher,
On Sat, Sep 30, 2017 at 1:23 AM, Christopher Howard
<address@hidden> wrote:
> Hi, I want to code a game using theChickadee framework, but I want to
> do it in an interactive programming environment, where I can evaluate
> things in the REPL while the Chickadee kernel is running, rather than
> needing to restart the kernel after each modification. The Chickadee
> kernel runs update hooks every so many milliseconds, so I think I just
> need to figure out a way to communicate code to an update hook, that it
> could execute. What would be the simplest and/or most sensible way to
> do this? (Threads? IPC? Communicate to a network port?)
Mark is right that a cooperative REPL server is the answer here. We
both worked on that feature a few years ago for exactly this purpose.
Here is a simple example program that has a REPL server added in:
(use-modules (chickadee)
(chickadee math vector)
(chickadee render sprite)
(chickadee render texture)
(system repl coop-server))
(define sprite #f)
(define repl #f)
(define (load)
(set! sprite (load-image "images/chickadee.png"))
(set! repl (spawn-coop-repl-server)))
(define (draw alpha)
(draw-sprite sprite (vec2 256.0 176.0)))
(define (update dt)
(poll-coop-repl-server repl))
(add-hook! load-hook load)
(add-hook! update-hook update)
(add-hook! draw-hook draw)
(add-hook! quit-hook abort-game)
(run-game)
Once the program is running, you can connect to the REPL server over a
tcp socket on port 37146. If you use Geiser, which I highly
recommend, just run `M-x connect-to-guile` and use the default
connection settings.
Hope this helps,
- Dave
- Re: Interactive programming with Event Loop?,
Thompson, David <=