From f89ad7bd1513536977fc093ad4390ece85b341b8 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sun, 6 Feb 2022 09:05:02 -0600 Subject: defined lazybones namespace for holding app instances --- clpmfile.lock | 6 ++++++ lazybones.asd | 3 ++- lazybones.lisp | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/clpmfile.lock b/clpmfile.lock index 650a906..874567c 100644 --- a/clpmfile.lock +++ b/clpmfile.lock @@ -58,6 +58,8 @@ ("lazybones-hunchentoot.asd" :version :newest :source :implicit-file :systems ("lazybones-hunchentoot")) ("lazybones.asd" :version :newest :source :implicit-file :systems ("lazybones")) +("lisp-namespace" :version "2021-10-21" :source "quicklisp" :systems + ("lisp-namespace")) ("md5" :version "2021-06-30" :source "quicklisp" :systems ("md5")) ("named-readtables" :version "2021-12-09" :source "quicklisp" :systems ("named-readtables")) @@ -87,6 +89,7 @@ :reverse-dependencies ("alexandria" ((:system :name "static-vectors") (:system :name "alexandria")) ((:system :name "proc-parse") (:system :name "alexandria")) + ((:system :name "lisp-namespace") (:system :name "alexandria")) ((:system :name "lazybones") (:system :name "alexandria")) ((:system :name "hunchentoot") (:system :name "alexandria")) ((:system :name "fast-io") (:system :name "alexandria")) @@ -164,6 +167,9 @@ ((:system :name "lazybones-hunchentoot") (:system :name "lazybones")) (t (:asd-file :name "lazybones.asd"))) +("lisp-namespace" + ((:system :name "lazybones") (:system :name "lisp-namespace"))) + ("md5" ((:system :name "hunchentoot") (:system :name "md5"))) ("named-readtables" diff --git a/lazybones.asd b/lazybones.asd index a0ee531..3a1326c 100644 --- a/lazybones.asd +++ b/lazybones.asd @@ -10,7 +10,8 @@ #:str #:cl-ppcre #:closer-mop - #:jonathan) + #:jonathan + #:lisp-namespace) :components ((:file "package") (:file "lazybones"))) diff --git a/lazybones.lisp b/lazybones.lisp index db1ca2a..3597c0e 100644 --- a/lazybones.lisp +++ b/lazybones.lisp @@ -18,6 +18,10 @@ "Dynamic variable holding the an APP instance. Dynamically bound by RUN-ENDPOINT so that it is available if needed in request handlers.") +;;; APP NAMESPACE + +(lisp-namespace:define-namespace lazybones) + ;;; LAZYBONES CLASSES (defclass app () @@ -35,6 +39,12 @@ :accessor app-endpoints :initform nil))) +(defmethod initialize-instance :after ((app app) &key) + (setf (symbol-lazybones (app-name app)) app)) + +(defun app (name) + (symbol-lazybones name nil)) + (defclass endpoint () ((method :reader endpoint-method @@ -167,7 +177,16 @@ Returns NIL on failure." (defun run-endpoint (endpoint args request response app) + "Bind dynamic variables *request* *response* and *app* before +applying HANDLER-FUNCTION slot of ENDPOINT to the ARGS list." (let ((*request* request) (*response* response) (*app* app)) (apply (endpoint-request-handler endpoint) args))) + +;;; ENDPOINT DEFINITION + +(defmacro defendpoint (appname method route-template (&key (auth nil)) &body body) + "Defines and installs an ENDPOINT instance to the APP instance +indicated by APPNAME, first checking an APP called APPNAME exits, +making a new one if not." ) -- cgit v1.2.3