|
1 | 1 | ;;; -*- mode:lisp; coding:utf-8 -*- |
2 | 2 |
|
3 | | - |
4 | 3 | ;;; |
5 | 4 | ;;; LOAD - load & compile Common Lisp file. |
6 | 5 | ;;; Simple implementation of the common Lisp function 'load' |
|
48 | 47 | (format t " ~a~%" x)) |
49 | 48 | t) |
50 | 49 | (error (msg) |
51 | | - (format t "Error: ~a~%" (!condition-args msg)) |
| 50 | + (typecase condition |
| 51 | + (simple-error |
| 52 | + (apply #'format t |
| 53 | + (simple-condition-format-control condition) |
| 54 | + (simple-condition-format-arguments condition))) |
| 55 | + (t (let* ((*print-escape* nil)) |
| 56 | + (print-object condition)))) |
52 | 57 | nil)) |
53 | 58 | nil) |
54 | 59 |
|
|
112 | 117 | ;;; |
113 | 118 | ;;; hook - #() store place for js-code |
114 | 119 | ;;; |
115 | | -;;; (setq bin #()) |
| 120 | +;;; IMPORTANT!! don't use literal #() (see Issue #345) |
| 121 | +;;; (setq bin (make-array 0 :fillpointer 0)) |
116 | 122 | ;;; (load "file1.lisp" :hook bin) |
117 | 123 | ;;; (load "file2.lisp" :hook bin) |
118 | 124 | ;;; (load "file3.lisp" :hook bin :output "lib.js") |
119 | 125 | ;;; => will be bundle js-code file1, file2, file3 from bin to "lib.js" |
120 | 126 | ;;; |
| 127 | +;;; |
121 | 128 | ;;; you will be use (require "./lib") or use html tag: |
122 | 129 | ;;; <script src="lib.js" type="text/javascript" charset="utf-8"></script> |
123 | 130 | ;;; without compilation. |
|
129 | 136 | (defun node-environment-p () |
130 | 137 | (if (find :node *features*) t)) |
131 | 138 |
|
| 139 | +;;; |
| 140 | +;;; how to bypass cors restrictions |
| 141 | +;;; 1. on the command line issue the command: |
| 142 | +;;; chrome.exe --user-data-dir="????????" --disable-web-security |
| 143 | +;;; will launch chrome in disbale-websecurity mode. (By path "????????" will be you Chrome account) |
| 144 | +;;; 2. enter devtool/source |
| 145 | +;;; 3. click add workspace |
| 146 | +;;; 4. add your folder with jscl.js, jscl-web.js, jscl.html |
| 147 | +;;; 5. allow devtool to work with the filesystem |
| 148 | +;;; all files from your directory will be loaded |
| 149 | +;;; 6. select the file JSCL.HTML and open it in a new tab |
| 150 | +;;; now, you can load: |
| 151 | +;;; source lisp files with the LOAD function |
| 152 | +;;; js files - with function JS-LOAD |
| 153 | +;;; css files - with function CSS-LOAD |
132 | 154 |
|
133 | 155 | (defun load (name &key verbose (sync (node-environment-p)) output place hook) |
134 | 156 | (terpri) |
|
142 | 164 | (loader-sync-mode name verbose output place hook) |
143 | 165 | (loader-async-mode name verbose output place hook))) |
144 | 166 | ;; browser platform |
145 | | - (t |
146 | | - (when sync |
147 | | - (warn "sync mode only for node/electron platform~%will be used async mode")) |
148 | | - (when (or output hook) |
149 | | - (warn "output/hook options only for node/electron platform")) |
150 | | - (loader-browser-mode name verbose))) |
| 167 | + (t (when sync |
| 168 | + (warn "sync mode only for node/electron platform~%will be used async mode")) |
| 169 | + (when (or output hook) |
| 170 | + (warn "output/hook options only for node/electron platform")) |
| 171 | + (warn "In browser mode, the LOAD function is executed ONLY if `web-security` is DISABLED (CORS restriction)") |
| 172 | + (loader-browser-mode name verbose))) |
151 | 173 | (values)) |
152 | 174 |
|
153 | 175 |
|
|
157 | 179 | (lambda (input) |
158 | 180 | (_load_form_eval_ (_ldr_ctrl-r_replace_ input) verbose)) |
159 | 181 | (lambda (url status) |
160 | | - (format t "~%Load: Can't load ~a~% Status ~%" url status)))) |
| 182 | + (format t "~%Load: Can't load ~a~% Status: ~a~%" url status)))) |
161 | 183 |
|
162 | 184 | ;;; alowe make bundle from source received from local fs (by FILE:) |
163 | | -;;; or from remote resource (by HTTP:) |
| 185 | +;;; or from remote resourse (by HTTP:) |
164 | 186 | (defun loader-async-mode (name verbose bundle-name place hook) |
165 | 187 | (_xhr_receiver_ |
166 | 188 | name |
167 | 189 | (lambda (input) |
168 | 190 | (_load_eval_bundle_ (_ldr_ctrl-r_replace_ input) verbose bundle-name place hook)) |
169 | 191 | (lambda (url status) |
170 | | - (format t "~%Load: Can't load ~a~% Status ~%" url status)))) |
| 192 | + (format t "~%Load: Can't load ~a~% Status: ~a~%" url status)))) |
171 | 193 |
|
172 | 194 | ;;; sync mode |
173 | 195 | (defun loader-sync-mode (name verbose bundle-name place hook) |
|
188 | 210 | (when bundle-name |
189 | 211 | (if hook |
190 | 212 | (setq code-stor hook) |
191 | | - (setq code-stor #())) |
| 213 | + ;; see Issue #345, #350, #397 |
| 214 | + (setq code-stor (make-array 0 :fill-pointer 0))) |
192 | 215 | (setq fbundle t)) |
193 | 216 | (setq stream (make-string-input-stream input)) |
194 | 217 | (tagbody sync-loader-rdr |
|
202 | 225 | (setq code (compile-toplevel expr t t)) |
203 | 226 | (setq rc (js-eval code)) |
204 | 227 | (when verbose (format t " ~a~%" rc)) |
205 | | - ;; so, expr already verified |
| 228 | + ;; so, expr already verifyed |
206 | 229 | ;; store expression after compilation/evaluated |
207 | 230 | (cond (fbundle ((oget code-stor "push") code)) |
208 | 231 | (hook ((oget code-stor "push") code)) |
209 | 232 | (t t)) )) |
210 | 233 | (error (msg) |
211 | | - (format t "Error: ~a~%" (!condition-args msg)) |
| 234 | + (format t " Error: ") |
| 235 | + (load_cond_err_handl_ msg) |
212 | 236 | ;; break read-eval loop |
213 | 237 | ;; no bundle |
214 | 238 | (setq fbundle nil) |
|
222 | 246 | (setq code-stor nil)) |
223 | 247 | (values))) |
224 | 248 |
|
| 249 | +;;; error message handle path |
| 250 | +(defun _load_cond_err_handl_(condition) |
| 251 | + (typecase condition |
| 252 | + (simple-error |
| 253 | + (apply #'format t |
| 254 | + (simple-condition-format-control condition) |
| 255 | + (simple-condition-format-arguments condition))) |
| 256 | + (type-error |
| 257 | + ;; note: |
| 258 | + ;; there can be custom event handling here. |
| 259 | + ;; while it remains as it was done. |
| 260 | + ;; sometime later |
| 261 | + (let* ((*print-escape* nil)) |
| 262 | + (print-object condition))) |
| 263 | + (t (let* ((*print-escape* nil)) |
| 264 | + (print-object condition)))) |
| 265 | + (write-char #\newline)) |
| 266 | + |
225 | 267 |
|
226 | 268 | ;;; Check what output directory exists |
227 | 269 | (defun _loader_check_output_directory_ (path) |
|
0 commit comments