diff --git a/README.md b/README.md index 8c50fa0..7d09820 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,12 @@ Sample CLOG app with code base so far (See tutorial 7 for a video game :) : (set-on-click hello-element ; Now we set a function to handle clicks (lambda (obj) ; In this case we use an anonymous function - (setf (color hello-element) "green"))))) + (setf (color hello-element) "green"))) + + (run body))) ; Keep our thread alive until connection closes + ; and prevent garbage collection of our CLOG-Objects + ; until no longer needed. + ;; To see all the events one can set and the many properties and styles that ;; exist, take a look through the CLOG manual or the file clog-element.lisp diff --git a/clog-body.lisp b/clog-body.lisp index 30b5e54..f8149ce 100644 --- a/clog-body.lisp +++ b/clog-body.lisp @@ -43,6 +43,22 @@ :navigator (make-clog-navigator connection-id)))) (set-body (html-document body) body))) +;;;;;;;;; +;; run ;; +;;;;;;;;; + +(defgeneric run (clog-body) + (:documentation "Keeps the main thread alive to prevent garbage +collection of local objects when not using connection-data objects +or global objects.")) + +(defmethod run ((obj clog-body)) + (loop + (if (validp obj) + (sleep 10) + (return (format t "Closing id ~A~%" + (connection-id obj)))))) + ;;;;;;;;;;;; ;; window ;; ;;;;;;;;;;;; diff --git a/clog.lisp b/clog.lisp index 2e0726f..085b3e5 100644 --- a/clog.lisp +++ b/clog.lisp @@ -309,6 +309,7 @@ application." (clog-body class) "CLOG-Body - Properties" + (run generic-function) (window generic-function) (html-document generic-function) (location generic-function) diff --git a/tutorial/01-tutorial.lisp b/tutorial/01-tutorial.lisp index b923311..d92cda9 100644 --- a/tutorial/01-tutorial.lisp +++ b/tutorial/01-tutorial.lisp @@ -23,7 +23,12 @@ (set-on-click hello-element ; Now we set a function to handle clicks (lambda (obj) ; In this case we use an anonymous function (declare (ignore obj)) - (setf (color hello-element) "green"))))) + (setf (color hello-element) "green"))) + + (run body))) ; Keep our thread alive until connection closes + ; and prevent garbage collection of our CLOG-Objects + ; until no longer needed. + ;; To see all the events one can set and the many properties and styles that ;; exist, take a look through the CLOG manual or the file clog-element.lisp diff --git a/tutorial/02-tutorial.lisp b/tutorial/02-tutorial.lisp index ddef493..7654a2d 100644 --- a/tutorial/02-tutorial.lisp +++ b/tutorial/02-tutorial.lisp @@ -27,7 +27,8 @@ (dotimes (n x) (create-child body (format nil "
Clicked ~A times.
" x)) - (scroll-to (window body) 0 (height body)))))))) + (scroll-to (window body) 0 (height body)))))) + (run body))) (defun start-tutorial () "Start turtorial." diff --git a/tutorial/03-tutorial.lisp b/tutorial/03-tutorial.lisp index f87a4fb..3452960 100644 --- a/tutorial/03-tutorial.lisp +++ b/tutorial/03-tutorial.lisp @@ -20,7 +20,8 @@ (dotimes (n x) (create-child body (format nil "Clicked ~A times.
" x)) - (sleep x))))))) + (sleep x))))) + (run body))) ;; Running this version of the last tutorial and clicking quickly on the (click me!) ;; will demonstrate an important aspect of CLOG, events can happen in _parallel_. diff --git a/tutorial/04-tutorial.lisp b/tutorial/04-tutorial.lisp index 6d374a8..fe39ec3 100644 --- a/tutorial/04-tutorial.lisp +++ b/tutorial/04-tutorial.lisp @@ -16,7 +16,9 @@ #'my-on-click) (set-on-click (create-child body "