add fast, direct (low-level) JS function calls for QML

This commit is contained in:
polos 2021-03-08 21:04:21 +01:00
parent bfdc227b21
commit 8d3bc5234f
11 changed files with 120 additions and 17 deletions

View file

@ -23,6 +23,7 @@
#:q<
#:q>
#:q>*
#:qjs
#:paint
#:scale
#:reload
@ -187,7 +188,7 @@
;;; JS
(defun js (item/name js-format-string &rest arguments)
"Evaluates a JS string, with 'this' bound to either ITEM, or first object matching NAME. Arguments are passed through FORMAT."
"Evaluates a JS string, with 'this' bound to either ITEM, or first object matching NAME. Arguments are passed through FORMAT. Use this function instead of the (faster) QJS if you need to evaluate generic JS code."
(qlet ((qml-exp "QQmlExpression(QQmlContext*,QObject*,QString)"
(root-context)
(quick-item item/name)
@ -200,3 +201,15 @@
(with-output-to-string (*standard-output*)
(print-js-readably object)))
(defun %qjs (item/name function-name &rest arguments)
;; QJS-CALL is defined in EQL5, function 'ecl_fun.cpp'
(eql::qjs-call (quick-item item/name) function-name arguments))
(defmacro qjs (function-name item/name &rest arguments)
"Fast and direct JS calls; max 10 arguments of type: T, NIL, INTEGER, FLOAT, STRING, (nested) LIST of mentioned types.
Examples:
(qjs |drawLine| *canvas* 0 0 100.0 100.0)
(qjs |drawPath| *canvas* (list (list 0 0) (list 0 10.0) (list 10.0 10.0)))"
`(%qjs ,item/name ,(symbol-name function-name) ,@arguments))