-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswank-eval-in-browser.lisp
39 lines (37 loc) · 1.49 KB
/
swank-eval-in-browser.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(in-package :cl-user)
(defun eval-in-browser (string &optional redraw)
(labels ((from-string (string)
(swank::with-buffer-syntax ()
(let ((*read-suppress* nil))
;; (values (read-from-string string))
(jscl::ls-read-from-string string))))
(emit-code (out)
(format out "(function(values, internals) {~%")
(format out "~A" (compile-arg))
(format out "})(jscl.internals.pv,jscl.internals);"))
(compile-arg ()
(if redraw
(compile-form
`(prog1
(jscl::lisp-to-js
(prin1-to-string
,(from-string string)))
(jscl::js-inline "window.m.redraw()"))
nil t)
(compile-form
`(jscl::lisp-to-js
(prin1-to-string
,(from-string string)))
nil t)))
(compile-form (form &optional multiple-value-p return-p)
(jscl::with-compilation-environment
(jscl::compile-toplevel form multiple-value-p return-p)))
(eval-in-browser ()
(let ((code
(with-output-to-string (out)
(emit-code out))))
;; (print code)
(SWANK:EVAL-IN-EMACS
`(skewer-eval-synchronously ,code)))))
(eval-in-browser)))
;; (eval-in-browser "(print 1)")