mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-05 18:20:36 -08:00
Make easier to use demos, change to boot.js in further prep for long polling as an option
This commit is contained in:
parent
18e617648f
commit
5237b518d4
8 changed files with 62 additions and 24 deletions
12
README.md
12
README.md
|
|
@ -57,7 +57,7 @@ To load this package and work through tutorials (assuming you
|
|||
have Quicklisp configured):
|
||||
|
||||
1. Start emacs then M-x slime
|
||||
2. In the REPL, run:
|
||||
2. In the REPL, run (tutorials current 1 - 18):
|
||||
|
||||
```
|
||||
CL-USER> (ql:quickload :clog)
|
||||
|
|
@ -70,11 +70,11 @@ To see where the source files are:
|
|||
CL-USER> (clog:clog-install-dir)
|
||||
```
|
||||
|
||||
You can the load the demos with:
|
||||
You can the run the demos with (currently 1 or 2):
|
||||
|
||||
```
|
||||
CL-USER> (load "path to clog/demos/01-snake.lisp")
|
||||
CL-USER> (clog-user:start-demo)
|
||||
CL-USER> (ql:quickload :clog)
|
||||
CL-USER> (clog-user:run-demo 1)
|
||||
```
|
||||
|
||||
To open a browser with the CLOG manual:
|
||||
|
|
@ -164,8 +164,8 @@ Tutorial Summary
|
|||
|
||||
Demo Summary
|
||||
|
||||
- 01-snake-game.lisp - Sparkey the Snake Game
|
||||
- 02-chat.lisp - Chat - Private instant messenger
|
||||
- 01-demo.lisp - Sparkey the Snake Game
|
||||
- 02-demo.lisp - Chat - Private instant messenger
|
||||
|
||||
Enhancements underway:
|
||||
|
||||
|
|
|
|||
|
|
@ -58,25 +58,25 @@ script."
|
|||
|
||||
(defvar *verbose-output* nil "Verbose server output (default false)")
|
||||
|
||||
(defvar *app* nil "Clack 'app' middle-ware")
|
||||
(defvar *client-handler* nil "Clack 'handler' for socket traffic")
|
||||
(defvar *on-connect-handler* nil "New connection event handler.")
|
||||
(defvar *app* nil "Clack 'app' middle-ware")
|
||||
(defvar *client-handler* nil "Clack 'handler' for socket traffic")
|
||||
|
||||
(defvar *new-id* 0 "Last issued connection or script IDs")
|
||||
(defvar *on-connect-handler* nil "New connection event handler.")
|
||||
|
||||
(defvar *connections* (make-hash-table) "Connections to IDs")
|
||||
(defvar *connection-ids* (make-hash-table) "IDs to connections")
|
||||
(defvar *connection-data* (make-hash-table) "Connection based data")
|
||||
|
||||
(defvar *connection-lock* (bordeaux-threads:make-lock)
|
||||
"Protect the connection hash tables")
|
||||
(defvar *queries-lock* (bordeaux-threads:make-lock)
|
||||
"Protect query hash tables")
|
||||
(defvar *id-lock* (bordeaux-threads:make-lock)
|
||||
|
||||
(defvar *new-id* 0 "Last issued connection or script IDs")
|
||||
(defvar *id-lock* (bordeaux-threads:make-lock)
|
||||
"Protect new-id variable.")
|
||||
|
||||
(defvar *queries* (make-hash-table) "Query ID to Answers")
|
||||
(defvar *queries-sems* (make-hash-table) "Query ID to semiphores")
|
||||
(defvar *queries-lock* (bordeaux-threads:make-lock)
|
||||
"Protect query hash tables")
|
||||
(defvar *query-time-out* 3 "Number of seconds to timeout waiting for a query")
|
||||
|
||||
(defvar *url-to-boot-file* (make-hash-table :test 'equalp) "URL to boot-file")
|
||||
|
|
@ -87,7 +87,6 @@ script."
|
|||
|
||||
(defun generate-id ()
|
||||
"Generate unique ids for use in connections and sripts."
|
||||
;; needs mutex or atomic
|
||||
(bordeaux-threads:with-lock-held (*id-lock*) (incf *new-id*)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
@ -207,7 +206,12 @@ the default answer. (Private)"
|
|||
(let ((ws (websocket-driver:make-server env)))
|
||||
(websocket-driver:on :open ws
|
||||
(lambda ()
|
||||
(let ((id (getf env :query-string)))
|
||||
(let* ((query (getf env :query-string))
|
||||
(items (when query
|
||||
(quri:url-decode-params query)))
|
||||
(id (when items
|
||||
(cdr (assoc "r" items
|
||||
:test #'equalp)))))
|
||||
(when (typep id 'string)
|
||||
(setf id (parse-integer id :junk-allowed t)))
|
||||
(handle-new-connection ws id))))
|
||||
|
|
@ -321,6 +325,8 @@ path by querying the browser. See PATH-NAME (CLOG-LOCATION)."
|
|||
(defun set-clog-path (path boot-file)
|
||||
(if boot-file
|
||||
(setf (gethash path *url-to-boot-file*)
|
||||
;; Make clog-path into a relative path of
|
||||
;; of site-root.
|
||||
(if (eql (char boot-file 0) #\/)
|
||||
(concatenate 'string "." boot-file)
|
||||
boot-file))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
(defpackage #:clog-user
|
||||
(:use #:cl #:clog)
|
||||
(:export start-tutorial))
|
||||
(:export start-tutorial start-demo))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Implementation - CLOG Utilities
|
||||
|
|
@ -41,12 +41,41 @@
|
|||
|
||||
(defun run-tutorial (num)
|
||||
"Run tutorial NUM"
|
||||
(load-tutorial num)
|
||||
(clog-user:start-tutorial))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;
|
||||
;; load-tutorial ;;
|
||||
;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun load-tutorial (num)
|
||||
"Load tutorial NUM - use (clog-user:start-tutorial)"
|
||||
(let ((p (merge-pathnames (format nil "./tutorial/~2,'0d-tutorial.lisp" num)
|
||||
(asdf:system-source-directory :clog))))
|
||||
(load p)
|
||||
(clog-user:start-tutorial)
|
||||
(format t "~%~% ---- The tutorial src is located at: ~A~%" p)))
|
||||
|
||||
;;;;;;;;;;;;;;
|
||||
;; run-demo ;;
|
||||
;;;;;;;;;;;;;;
|
||||
|
||||
(defun run-demo (num)
|
||||
"Run demo NUM"
|
||||
(load-demo num)
|
||||
(clog-user:start-demo))
|
||||
|
||||
;;;;;;;;;;;;;;;
|
||||
;; load-demo ;;
|
||||
;;;;;;;;;;;;;;;
|
||||
|
||||
(defun load-demo (num)
|
||||
"Load demo NUM - use (clog-user:start-demo)"
|
||||
(let ((p (merge-pathnames (format nil "./demos/~2,'0d-demo.lisp" num)
|
||||
(asdf:system-source-directory :clog))))
|
||||
(load p)
|
||||
(format t "~%~% ---- The demo src is located at: ~A~%" p)))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;
|
||||
;; load-world ;;
|
||||
;;;;;;;;;;;;;;;;
|
||||
|
|
|
|||
|
|
@ -742,6 +742,9 @@ embedded in a native template application.)"
|
|||
(clog-install-dir function)
|
||||
(open-manual function)
|
||||
(run-tutorial function)
|
||||
(load-tutorial function)
|
||||
(run-demo function)
|
||||
(load-demo function)
|
||||
|
||||
"Functions for Compilation and Documentation"
|
||||
(load-world function)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ To load "clog":
|
|||
Load the demo:
|
||||
|
||||
```
|
||||
CL-USER> (load "/Users/dbotton/common-lisp/clog/demos/01-hello.lisp")
|
||||
#P"/Users/dbotton/common-lisp/clog/demos/01-hello.lisp"
|
||||
CL-USER> (load "/Users/dbotton/common-lisp/clog/demos/01-demo.lisp")
|
||||
#P"/Users/dbotton/common-lisp/clog/demos/01-demo.lisp"
|
||||
```
|
||||
|
||||
Start the demo:
|
||||
|
|
@ -34,5 +34,5 @@ Most demos startup a browser, if not use http://127.0.0.1:8080
|
|||
|
||||
Demo Summary
|
||||
|
||||
- 01-snake-game.lisp - Sparkey the Snake Game
|
||||
- 02-chat.lisp - Chat - Private instant messenger
|
||||
- 01-demo.lisp - Sparkey the Snake Game
|
||||
- 02-demo.lisp - Chat - Private instant messenger
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ function Setup_ws() {
|
|||
ws.onerror = function (event) {
|
||||
console.log ("onerror: reconnect");
|
||||
ws = null;
|
||||
ws = new WebSocket (adr + "?" + clog['connection_id']);
|
||||
ws = new WebSocket (adr + "?r=" + clog['connection_id']);
|
||||
ws.onopen = function (event) {
|
||||
console.log ("onerror: reconnect successful");
|
||||
Setup_ws();
|
||||
|
|
@ -56,7 +56,7 @@ function Setup_ws() {
|
|||
ws.onclose = function (event) {
|
||||
console.log ("onclose: reconnect");
|
||||
ws = null;
|
||||
ws = new WebSocket (adr + "?" + clog['connection_id']);
|
||||
ws = new WebSocket (adr + "?r=" + clog['connection_id']);
|
||||
ws.onopen = function (event) {
|
||||
console.log ("onclose: reconnect successful");
|
||||
Setup_ws();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue