mirror of
https://github.com/rabbibotton/clog.git
synced 2026-01-01 06:41:11 -08:00
Better REPL support
This commit is contained in:
parent
18b160fb2c
commit
bbe3c6d56c
4 changed files with 100 additions and 82 deletions
|
|
@ -122,25 +122,29 @@ To load \"clog\":
|
|||
(:CLOG)
|
||||
```
|
||||
|
||||
Next, we need to use the INITIALIZE function to tell CLOG to start up the web
|
||||
server, what to do when someone connects and where the static HTML files
|
||||
are located.
|
||||
Next, we tell clog to start a clog-repl:
|
||||
|
||||
```lisp
|
||||
CL-USER> (clog:initialize (lambda (body)()) :static-root #P\"~/common-lisp/clog/static-files/\")
|
||||
CL-USER> (clog:clog-repl)
|
||||
Hunchentoot server is started.
|
||||
Listening on 0.0.0.0:8080.
|
||||
HTTP listening on : 0.0.0.0:8080
|
||||
HTML Root : /Users/dbotton/common-lisp/clog/static-files/
|
||||
Boot file for path / : /boot.html
|
||||
HTML Root : ~/common-lisp/clog/static-files/
|
||||
Boot file for path / : /debug.html
|
||||
|
||||
Use clog-user:*body* to access the clog-repl window.
|
||||
NIL
|
||||
```
|
||||
|
||||
At this point our CLOG app does very little. To see our CLOG app so far go to
|
||||
http://127.0.0.1:8008 or in most common-list configurations you can use:
|
||||
At this point CLOG should open a browser window to
|
||||
http://127.0.0.1:8008/repl
|
||||
|
||||
We can new enter the clog-user package and hack a way.
|
||||
|
||||
```lisp
|
||||
CL-USER> (clog:open-browser)
|
||||
CL-USER> (in-package clog-user)
|
||||
#<\"CLOG-USER\" package>
|
||||
CLOG-USER> (setf (background-color *body*) :red)
|
||||
```
|
||||
|
||||
Something more than an empty lambda function is needed to do more. The
|
||||
|
|
@ -148,18 +152,6 @@ tutorials are a good place to start with make CLOG apps in code, so
|
|||
here we are going to demonstrate the concepts using some REPL tricks
|
||||
to help developing CLOG apps in general.
|
||||
|
||||
We need to give ourselves easier access to CLOG and or an app we are
|
||||
working one. Let's create a package that uses CLOG and of course
|
||||
common lisp \"cl\" we will call it \"clog-user\".
|
||||
|
||||
```lisp
|
||||
CL-USER> (defpackage #:clog-user
|
||||
(:use #:cl #:clog))
|
||||
(in-package :clog-user)
|
||||
#<\"CLOG-USER\" package>
|
||||
CLOG-USER>
|
||||
```
|
||||
|
||||
Since we already initialized CLOG let's use SET-ON-NEW-WINDOW to change our
|
||||
on-new-window handler (handler is just a made up name for a function that
|
||||
will handle an event).
|
||||
|
|
@ -168,23 +160,7 @@ will handle an event).
|
|||
CLOG-USER> (set-on-new-window (lambda (body) (create-div body :content \"Hello World!\")))
|
||||
```
|
||||
|
||||
Now go ahead and resresh our browser and you should see the famous first words
|
||||
of every app.
|
||||
|
||||
This of though is still not very REPL like, CLOG is a 'live' connection to a
|
||||
browser. So lets redo our on-new-window handler to give us access to the
|
||||
browser in the REPL.
|
||||
|
||||
```lisp
|
||||
CLOG-USER> (defparameter *body* nil)
|
||||
*BODY*
|
||||
CLOG-USER> (set-on-new-window (lambda (body) (setf *body* body)))
|
||||
```
|
||||
|
||||
Reset your browser again (or navigate to http://127.0.0.1:8080 and let's have
|
||||
some fun.
|
||||
|
||||
(From here on, we will leave out the promps and responses in our quotes of
|
||||
(From here on, we will leave out the prompts and responses in our quotes of
|
||||
code.)
|
||||
|
||||
```lisp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue