Add dlambda + contextl hack
[clinton/lisp-on-lines.git] / src / ucw / contextl-components.lisp
CommitLineData
eaf8cd9c 1(in-package :lisp-on-lines-ucw)
2
8032a7fe 3(defmacro dlambda ((&rest args) &body body)
4 (let ((env (gensym)))
5 `(let ((,env (capture-dynamic-environment)))
6 (lambda (,@args)
7 (with-dynamic-environment (,env)
8 ,@body)))))
9
10(export '(dlambda) :lisp-on-lines-ucw)
11
6963098f 12(defclass contextl-application (standard-application)
13 ()
14 (:default-initargs
15
16 :action-class 'contextl-action))
17
18(defclass contextl-action (ucw-standard:standard-action)
19 ((dynamic-environment :accessor action-dynamic-environment
20 :initform nil
21 :initarg :dynamic-environment))
22 (:metaclass closer-mop:funcallable-standard-class))
23
24(defmethod shared-initialize :after ((action contextl-action) slots &rest args)
25 (declare (ignore slots args))
26 (setf (action-dynamic-environment action) (capture-dynamic-environment)))
27
28(defmethod ucw-core:handle-action :wrap-around ((action contextl-action) application session frame)
29 (call-next-method))
30
31(defmethod ucw-core:call-action :around ((action contextl-action) application session frame)
32 (with-dynamic-environment ((action-dynamic-environment action))
33 (call-next-method)))
34
8032a7fe 35(defmethod ucw-core:call-callbacks :around ((action contextl-action) frame request)
6963098f 36 (with-dynamic-environment ((action-dynamic-environment action))
37 (call-next-method)))
38
8032a7fe 39
6963098f 40(defclass contextl-component (standard-component)
41 ((component-dynamic-environment :accessor component-dynamic-environment
42 :initform nil))
43 (:metaclass standard-component-class))
44
45(defmethod render :wrap-around ((component contextl-component))
46 (if (component-dynamic-environment component)
47 (with-dynamic-environment ((component-dynamic-environment component))
48 (call-next-method))
49 (progn (setf (component-dynamic-environment component) (capture-dynamic-environment))
50 (call-next-method))))
51
52(defmethod/cc call-component :before ((from t) (to contextl-component))
53 (setf (component-dynamic-environment to) (capture-dynamic-environment)))
54
55
56
57
58#+LOL-TEST(progn
59 (defclass contextl-test-application (contextl-application)
60 ()
61 (:default-initargs :url-prefix "/contextl/"))
62
63 (defparameter *context-test-application* (make-instance 'contextl-test-application))
64
65 (register-application ucw-user:*example-server* *context-test-application*)
66
67 (defentry-point "test.ucw" (:application *context-test-application*) ()
68 (call 'contextl-test-component))
69
70 (defdynamic foo 1)
71
72(defclass contextl-test-component (contextl-component) ()
73 (:metaclass standard-component-class))
74
75(defmethod render ((component contextl-test-component))
76 (<:As-html (dynamic foo))
77 (dlet ((foo (1+ (dynamic foo))))
78 (<:as-html (dynamic foo))
79 (<:br)
80 (with-described-object (T nil)
81 (let ((a (find-attribute *description* 'identity)))
82 (<ucw:a :action (call 'contextl-test-component)
83 "Call")))
84 (<:br)
85 (when (component.calling-component component)
86 (<ucw:a :action (answer)
87 "Answer")))
88))
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
eaf8cd9c 105#+nil (defclass contextl-session-frame (ucw-core::standard-session-frame)
106 ())
107
108#+nil(defmethod ucw-core::register-callback-in-frame ((frame contextl-session-frame) callback &key &allow-other-keys)
109 (let ((lambda (ucw::callback-lambda callback)))
110 (let ((context (contextl:current-layer-context)))
111 (setf (ucw::callback-lambda callback)
112 (lambda (arg)
113 (contextl:funcall-with-layer-context context lambda arg)))
114 (call-next-method))))
115
116#+nil(setf ucw-core::*session-frame-class* 'contextl-session-frame)
117
118