mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-06 02:30:38 -08:00
add support for keyword arguments in 'Lisp.call()', like '":start", 10'
This commit is contained in:
parent
a3879f7288
commit
eb67c56fd2
1 changed files with 18 additions and 9 deletions
|
|
@ -38,24 +38,33 @@
|
|||
;; Every 'Lisp.call()' or 'Lisp.apply()' function call in QML will call this
|
||||
;: function. The variable *CALLER* will be bound to the calling QQuickItem,
|
||||
;; if passed with 'this' as first argument to 'Lisp.call()' / 'Lisp.apply()'.
|
||||
;;
|
||||
;; Possible integers encoded as hex strings in JS (see function HEX above)
|
||||
;; are automatically converted back to integers.
|
||||
;;
|
||||
;; Strings starting with ':' are assumed to be Lisp keywords, if composed by
|
||||
;; alphanumeric characters, and if they have a following argument.
|
||||
(let ((fun (string-to-symbol function))
|
||||
(*caller* (if (zerop caller)
|
||||
*caller*
|
||||
(qt-object caller))))
|
||||
(if (fboundp fun)
|
||||
(apply fun (mapcar (lambda (arg)
|
||||
(if (and (stringp arg)
|
||||
(x:starts-with "#x" arg))
|
||||
(apply fun (let ((len (length arguments)))
|
||||
(loop :for arg :in arguments
|
||||
:for n :from 1 :to len
|
||||
:collect (if (and (stringp arg)
|
||||
(or (x:starts-with "#x" arg) ; integer
|
||||
(and (char= #\: (char arg 0)) ; keyword
|
||||
(> (length arg) 1)
|
||||
(every 'alphanumericp (subseq arg 1))
|
||||
(< n len))))
|
||||
(or (ignore-errors (read-from-string arg))
|
||||
arg)
|
||||
arg))
|
||||
arguments))
|
||||
arg))))
|
||||
(let ((msg (format nil "[LQML:error] Lisp.call(): ~S is undefined." function)))
|
||||
(when *break-on-errors*
|
||||
(break msg)
|
||||
(format *error-output* "~%~A~%" msg))))))
|
||||
(break msg))
|
||||
(format *error-output* "~%~A~%" msg)))))
|
||||
|
||||
;;; utils
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue