mirror of
https://gitlab.com/eql/EQL5.git
synced 2025-12-06 10:31:19 -08:00
"qml-lisp": allow for nested lists, vectors etc. as return values from QML function calls; some revisions;
This commit is contained in:
parent
4cb7bfcfbf
commit
f290094824
10 changed files with 119 additions and 25 deletions
|
|
@ -34,13 +34,44 @@
|
|||
|
||||
;;; function calls from QML
|
||||
|
||||
(defun print-js-readably (object)
|
||||
"Prints lists, vectors, T, NIL, floats in JS notation, which will be passed to JS 'eval()'."
|
||||
(if (and (not (stringp object))
|
||||
(vectorp object))
|
||||
(print-js-readably (coerce object 'list))
|
||||
(typecase object
|
||||
(cons
|
||||
(write-char #\[)
|
||||
(do ((list object (rest list)))
|
||||
((null list) (write-char #\]))
|
||||
(print-js-readably (first list))
|
||||
(when (rest list)
|
||||
(write-char #\,))))
|
||||
(float
|
||||
;; cut off Lisp specific notations
|
||||
(princ (string-right-trim "dl0" (princ-to-string object))))
|
||||
(t
|
||||
(cond ((eql 't object)
|
||||
(princ "true"))
|
||||
((eql 'nil object)
|
||||
(princ "false"))
|
||||
(t
|
||||
(prin1 object)))))))
|
||||
|
||||
(defun print-to-js-string (object)
|
||||
(with-output-to-string (*standard-output*)
|
||||
(princ "#<>") ; mark for passing to JS "eval()"
|
||||
(print-js-readably object)))
|
||||
|
||||
(defun qml-apply (function arguments)
|
||||
"Every 'Lisp.fun()' or 'Lisp.apply()' function call in QML will call this function."
|
||||
(let ((value (apply (string-to-symbol function)
|
||||
(let ((object (apply (string-to-symbol function)
|
||||
arguments)))
|
||||
(if (stringp value)
|
||||
value
|
||||
(princ-to-string value))))
|
||||
(if (stringp object)
|
||||
object
|
||||
(print-to-js-string object))))
|
||||
|
||||
;;; utils
|
||||
|
||||
(let (root-object)
|
||||
(defun root-object ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue