Browse code
feature: convenience functions in demo-app, use data extractors
Ed Langley authored on 21/10/2019 04:02:52
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -18,6 +18,10 @@ |
18 | 18 |
(b :char) |
19 | 19 |
(c :boolean)) |
20 | 20 |
|
21 |
+(defmacro selector-lambda (selector &rest args) |
|
22 |
+ `(lambda (receiver) |
|
23 |
+ [receiver ,selector ,@args])) |
|
24 |
+ |
|
21 | 25 |
(cffi:defcfun (init-with-frame "initWithFrame") |
22 | 26 |
:pointer |
23 | 27 |
(thing :pointer) |
... | ... |
@@ -25,7 +29,7 @@ |
25 | 29 |
|
26 | 30 |
(cffi:defcfun (print-rect "printRect") |
27 | 31 |
:void |
28 |
- (rect (:struct objc-runtime::ns-rect))) |
|
32 |
+ (rect (:struct objc-runtime:ns-rect))) |
|
29 | 33 |
|
30 | 34 |
(cffi:defcfun (set-uncaught-exception-handler "set_uncaught_exception_handler" |
31 | 35 |
:library objc-runtime::expose-stuff) |
... | ... |
@@ -121,11 +125,13 @@ |
121 | 125 |
[[cls @(alloc)] @(init)]) |
122 | 126 |
|
123 | 127 |
(defun make-button-delegate (button cb) |
124 |
- (let ((my-class (objc-runtime::objc-allocate-class-pair #@NSObject "ButtonDel" 0))) |
|
125 |
- (objc-runtime::class-add-method my-class @(doMagic) cb "v@:@") |
|
126 |
- (fw.lu:prog1-bind (result (alloc-init my-class)) |
|
127 |
- [button @(setTarget) :pointer result] |
|
128 |
- [button @(setAction) :pointer @(doMagic)]))) |
|
128 |
+ (objc-runtime.data-extractors:objc-typecase button |
|
129 |
+ (#@NSButton (let ((my-class (objc-runtime::objc-allocate-class-pair #@NSObject "ButtonDel" 0))) |
|
130 |
+ (objc-runtime::class-add-method my-class @(doMagic) cb "v@:@") |
|
131 |
+ (fw.lu:prog1-bind (result (alloc-init my-class)) |
|
132 |
+ [button @(setTarget:) :pointer result] |
|
133 |
+ [button @(setAction:) :pointer @(doMagic)]))) |
|
134 |
+ (t (format t "~&The button is not a button~%")))) |
|
129 | 135 |
|
130 | 136 |
(defun make-app-delegate-class (outlets) |
131 | 137 |
(let ((app-delegate-class (objc-runtime::objc-allocate-class-pair |
... | ... |
@@ -138,13 +144,24 @@ |
138 | 144 |
|
139 | 145 |
app-delegate-class)) |
140 | 146 |
|
147 |
+(defun make-app-delegate-class-with-props (foo outlets) |
|
148 |
+ (let ((app-delegate-class (objc-runtime::objc-allocate-class-pair |
|
149 |
+ #@NSObject foo 0))) |
|
150 |
+ (objc-runtime:add-pointer-ivar app-delegate-class "window") |
|
151 |
+ (objc-runtime:add-pointer-ivar app-delegate-class "delegate") |
|
152 |
+ |
|
153 |
+ (loop for outlet in outlets do |
|
154 |
+ (objc-runtime:add-pointer-ivar app-delegate-class outlet)) |
|
155 |
+ |
|
156 |
+ app-delegate-class)) |
|
157 |
+ |
|
141 | 158 |
|
142 | 159 |
(defun load-nib (name) |
143 | 160 |
;; find and activate the nib |
144 | 161 |
(let* ((bundle [#@NSBundle @(mainBundle)]) |
145 | 162 |
(nib [[#@NSNib @(alloc)] @(initWithNibNamed:bundle:) |
146 |
- :pointer (objc-runtime::make-nsstring name) |
|
147 |
- :pointer bundle])) |
|
163 |
+ :pointer (objc-runtime::make-nsstring name) |
|
164 |
+ :pointer bundle])) |
|
148 | 165 |
(cffi:with-foreign-object (p :pointer) |
149 | 166 |
;; TODO: is dropping p a problem here? The docs say something relevant. |
150 | 167 |
;; must investigate. |