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

@ -6,7 +6,7 @@
(defvar *canvas* "canvas")
(defun draw-line (x1 y1 x2 y2)
(js *canvas* "drawLine(~D, ~D, ~D, ~D)"
(qjs |drawLine| *canvas*
x1 y1 x2 y2))
(defun draw-number (number)

View file

@ -25,6 +25,7 @@
#:q<
#:q>
#:q>*
#:qjs
#:paint
#:scale
#:reload
@ -196,7 +197,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."
(qrun* (qlet ((qml-exp "QQmlExpression(QQmlContext*,QObject*,QString)"
(root-context)
(quick-item item/name)
@ -209,6 +210,17 @@
(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))
;;; ini
(defun ini-quick-view (file)

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))

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))

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))

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))

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))

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))

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))

View file

@ -978,11 +978,11 @@ static QVariantList lispToQVariantList(cl_object l_list) {
l << QVariant(toQString(l_el)); }
else if(l_el == ECL_T) { // true
l << QVariant(true); }
else if(l_el == ECL_NIL) { // null
l << QVariant(); }
else if(l_el == ECL_NIL) { // false
l << QVariant(false); }
else if(LISTP(l_el)) { // list
l << QVariant::fromValue(lispToQVariantList(l_el)); }
else { // null
else { // default: undefined
l << QVariant(); }
l_do_list = cl_cdr(l_do_list); }}
return l; }
@ -3066,11 +3066,11 @@ cl_object qjs_call(cl_object l_item, cl_object l_name, cl_object l_args) {
arg[i] = QVariant(toQString(l_arg)); }
else if(l_arg == ECL_T) { // true
arg[i] = QVariant(true); }
else if(l_arg == ECL_NIL) { // null
arg[i] = QVariant(); }
else if(l_arg == ECL_NIL) { // false
arg[i] = QVariant(false); }
else if(LISTP(l_arg)) { // list
arg[i] = QVariant::fromValue(lispToQVariantList(l_arg)); }
else { // default: null
else { // default: undefined
arg[i] = QVariant(); }
genA[i] = QGenericArgument(v, &arg[i]);
l_do_args = cl_cdr(l_do_args); }

View file

@ -9,7 +9,7 @@
#include <QStringList>
#include <QDebug>
const char EQL::version[] = "20.7.1"; // July 2020
const char EQL::version[] = "21.3.1"; // March 2021
extern "C" void ini_EQL(cl_object);