From 75f1d78209d7e4b60fff364c3d5a1ca017dd8664 Mon Sep 17 00:00:00 2001 From: David Botton Date: Tue, 5 Jan 2021 19:10:06 -0500 Subject: [PATCH] Restart easier and tutorial --- clog-system.lisp | 19 ++++++++++++------- tutorial/01-tutorial.lisp | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 tutorial/01-tutorial.lisp diff --git a/clog-system.lisp b/clog-system.lisp index cd8885f..426b4d5 100644 --- a/clog-system.lisp +++ b/clog-system.lisp @@ -33,14 +33,18 @@ (static-root #P"./static-files/")) "Inititalze CLOG on a socket using HOST and PORT to serve BOOT-FILE as the default route to establish web-socket connections and static files -located at STATIC-ROOT." - (setf *on-new-window* on-new-window-handler) +located at STATIC-ROOT. If CLOG was already initialized and not shut +down, this function does the same as set-on-new-window." + (if *on-new-window* + (set-on-new-window on-new-window-handler) + (progn + (set-on-new-window on-new-window-handler) - (cc:initialize #'on-connect - :host host - :port port - :boot-file boot-file - :static-root static-root)) + (cc:initialize #'on-connect + :host host + :port port + :boot-file boot-file + :static-root static-root)))) ;;;;;;;;;;;;;;;;;;;;;;; ;; set-on-new-window ;; @@ -56,4 +60,5 @@ located at STATIC-ROOT." (defun shutdown () "Shutdown CLOG." + (set-on-new-window nil) (cc:shutdown-clog)) diff --git a/tutorial/01-tutorial.lisp b/tutorial/01-tutorial.lisp new file mode 100644 index 0000000..1a7af8b --- /dev/null +++ b/tutorial/01-tutorial.lisp @@ -0,0 +1,27 @@ +(defpackage #:clog-user ; Setup a package for our work to exist in + (:use #:cl #:clog) ; Use the Common Lisp language and CLOG + (:export start-tutorial)) ; Export as public the start-tutorial function + +(in-package :clog-user) ; Tell the "reader" we are in the clog-user package + + +;; Define our CLOG application + +(defun on-new-window (win) ; define a function to be called + (create-child win "

Hello World!

")) + + + +(defun start-tutorial () ; Define the function called start-tutorial + "Start turtorial." ; Optional docstring to describe function + + ;; Initialize the CLOG system + (initialize #'on-new-window) + ;; Set the function on-new-window to execute + ;; everytime a browser connection to our app. + ;; #' tells common lisp to pass the function + ;; to intialize and not to execute it. + + + ;; Open a browser to http://12.0.0.1:8080 - the default for CLOG apps + (open-browser))