Add a simple protectable main loop
If an error occurs, a `continue' restart can be invoked to resume the program execution. Also, if the main loop is called through the slime repl, it will still be able to run on the main thread.
This commit is contained in:
parent
0d5ab4faa9
commit
9a0872cd33
3 changed files with 56 additions and 3 deletions
|
|
@ -5,7 +5,28 @@
|
|||
|
||||
(in-package :cl-user)
|
||||
(defpackage stoe
|
||||
(:use :cl))
|
||||
(:use :cl
|
||||
:utils))
|
||||
(in-package :stoe)
|
||||
|
||||
;; blah blah blah.
|
||||
(defun initialize (&optional argv)
|
||||
"Perform the engine and subsystems initialization process."
|
||||
(format t "Initialize..."))
|
||||
|
||||
(defun finalize ()
|
||||
"Perform the engine and subsystems finalization process."
|
||||
(format t "Finalize..."))
|
||||
|
||||
(defun main-loop (&optional unprotected)
|
||||
"Run the protected main-loop. An error will be catched with the possibility to
|
||||
continue unless `unprotected' is t."
|
||||
(catch 'exit-main-loop
|
||||
(loop (restartable unprotected
|
||||
(eval-repl)
|
||||
(sleep 0.01)))))
|
||||
|
||||
(defun main (&optional argv)
|
||||
"Run the program."
|
||||
(initialize argv)
|
||||
(main-loop)
|
||||
(finalize))
|
||||
|
|
|
|||
30
src/utils.lisp
Normal file
30
src/utils.lisp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#|
|
||||
This file is a part of stoe project.
|
||||
Copyright (c) 2014 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|
||||
|#
|
||||
|
||||
(in-package :cl-user)
|
||||
(defpackage stoe.utils
|
||||
(:use :cl)
|
||||
(:nicknames :utils)
|
||||
(:export :restartable
|
||||
:eval-repl))
|
||||
(in-package :stoe.utils)
|
||||
|
||||
(defmacro restartable (unprotected &body body)
|
||||
"Provide a Continue restart unless unprotected is t."
|
||||
`(if ,unprotected
|
||||
(progn
|
||||
,@body)
|
||||
(restart-case
|
||||
(progn
|
||||
,@body)
|
||||
(continue () :report "Continue"))))
|
||||
|
||||
(defun eval-repl ()
|
||||
"Eval the repl if the main-loop is run through it."
|
||||
#+swank
|
||||
(let ((conn (or swank::*emacs-connection*
|
||||
(swank::default-connection))))
|
||||
(when conn
|
||||
(swank::handle-requests conn t))))
|
||||
4
stoe.asd
4
stoe.asd
|
|
@ -21,7 +21,9 @@
|
|||
:depends-on ()
|
||||
:components ((:module "src"
|
||||
:components
|
||||
((:file "stoe"))))
|
||||
((:file "utils")
|
||||
(:file "stoe"
|
||||
:depends-on ("utils")))))
|
||||
:description "SaintOEngine - A 3d engine in common-lisp"
|
||||
:long-description
|
||||
#.(with-open-file (stream (merge-pathnames
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue