mirror of
https://gitlab.com/eql/EQL5.git
synced 2026-01-04 08:11:46 -08:00
review "qml-lisp"
This commit is contained in:
parent
03c7a5ded5
commit
140e793040
6 changed files with 77 additions and 29 deletions
|
|
@ -5,5 +5,7 @@ RUN
|
|||
|
||||
Please run it from this directory.
|
||||
|
||||
(For Emacs/Slime, this would be: eql5 ~/slime/eql-start-swank.lisp)
|
||||
For Emacs/Slime, this would be:
|
||||
|
||||
eql5 ~/slime/eql-start-swank.lisp example
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,14 @@
|
|||
#-qt-wrapper-functions ; see README-OPTIONAL.txt
|
||||
(load (in-home "src/lisp/all-wrappers"))
|
||||
|
||||
(require :qml-lisp "qml-lisp")
|
||||
|
||||
(qrequire :quick)
|
||||
|
||||
(defun example-url (name)
|
||||
(|fromLocalFile.QUrl| (in-home (x:cc "examples/M-modules/quick/qml-lisp/qml/" name))))
|
||||
(require :qml-lisp "qml-lisp")
|
||||
|
||||
;;; QQuickView
|
||||
|
||||
(defvar *quick-view* (qnew "QQuickView(QUrl)" (example-url "example.qml")))
|
||||
(defvar *quick-view* (qnew "QQuickView(QUrl)"
|
||||
(|fromLocalFile.QUrl| "qml/example.qml")))
|
||||
|
||||
(defun run ()
|
||||
(|setResizeMode| *quick-view* |QQuickView.SizeRootObjectToView|)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
#include "qml_lisp.h"
|
||||
#include <eql_fun.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static Lisp* lisp = 0;
|
||||
|
||||
static QObject* lisp_provider(QQmlEngine*, QJSEngine*) { return lisp; }
|
||||
|
||||
QObject* ini() {
|
||||
if(!lisp) {
|
||||
lisp = new Lisp;
|
||||
qmlRegisterSingletonType<Lisp>("EQL5", 1, 0, "Lisp", lisp_provider); }
|
||||
return lisp; }
|
||||
|
||||
QString Lisp::fun(const QString& function,
|
||||
const QVariant& argument1, const QVariant& argument2, const QVariant& argument3,
|
||||
const QVariant& argument4, const QVariant& argument5, const QVariant& argument6,
|
||||
const QVariant& argument7, const QVariant& argument8, const QVariant& argument9) {
|
||||
QVariantList arguments;
|
||||
if(!argument1.isNull()) {
|
||||
arguments << argument1;
|
||||
if(!argument2.isNull()) {
|
||||
arguments << argument2;
|
||||
if(!argument3.isNull()) {
|
||||
arguments << argument3;
|
||||
if(!argument4.isNull()) {
|
||||
arguments << argument4;
|
||||
if(!argument5.isNull()) {
|
||||
arguments << argument5;
|
||||
if(!argument6.isNull()) {
|
||||
arguments << argument6;
|
||||
if(!argument7.isNull()) {
|
||||
arguments << argument7;
|
||||
if(!argument8.isNull()) {
|
||||
arguments << argument8;
|
||||
if(!argument9.isNull()) {
|
||||
arguments << argument9; }}}}}}}}}
|
||||
return apply(function, arguments); }
|
||||
|
||||
QString Lisp::apply(const QString& function, const QVariantList& arguments) {
|
||||
QVariant ret =
|
||||
eql_fun("eql::qml-apply", QVariant::String,
|
||||
Q_ARG(QString, function),
|
||||
Q_ARG(QVariantList, arguments));
|
||||
return ret.toString(); }
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
#define LIB_H
|
||||
|
||||
#include <QtQml>
|
||||
#include <eql_fun.h>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#define LIB_EXPORT __declspec(dllexport)
|
||||
|
|
@ -12,30 +11,20 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
extern "C" { LIB_EXPORT QObject* ini(); }
|
||||
|
||||
class Lisp : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Q_INVOKABLE QString apply(const QString& function, const QVariantList& arguments = QVariantList()) {
|
||||
QVariant ret =
|
||||
eql_fun("eql::qml-apply", QVariant::String,
|
||||
Q_ARG(QString, function),
|
||||
Q_ARG(QVariantList, arguments));
|
||||
return ret.toString(); }
|
||||
Q_INVOKABLE QString fun(const QString&, // function name plus max. 9 arguments
|
||||
const QVariant& = QVariant(), const QVariant& = QVariant(), const QVariant& = QVariant(),
|
||||
const QVariant& = QVariant(), const QVariant& = QVariant(), const QVariant& = QVariant(),
|
||||
const QVariant& = QVariant(), const QVariant& = QVariant(), const QVariant& = QVariant());
|
||||
|
||||
Q_INVOKABLE QString apply(const QString&, const QVariantList& = QVariantList());
|
||||
};
|
||||
|
||||
static Lisp* lisp = 0;
|
||||
|
||||
static QObject* lisp_provider(QQmlEngine*, QJSEngine*) { return lisp; }
|
||||
|
||||
extern "C" {
|
||||
LIB_EXPORT QObject* ini() {
|
||||
if(!lisp) {
|
||||
lisp = new Lisp;
|
||||
qmlRegisterSingletonType<Lisp>("EQL5", 1, 0, "Lisp", lisp_provider); }
|
||||
return lisp; }
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,11 +6,22 @@ Item {
|
|||
|
||||
Component.onCompleted: {
|
||||
|
||||
console.log(Lisp.apply("format", [null, "~R", 123])) // (1) call CL function
|
||||
// PLEASE NOTE:
|
||||
//
|
||||
// * for calling any CL or EQL function with max. 9 arguments, use Lisp.fun()
|
||||
// * for either more than 9 arguments or passing (nested) lists, use Lisp.apply()
|
||||
|
||||
console.log(Lisp.apply("x:join", [["11", "55"], ":"])) // (2) nested arrays are possible
|
||||
// (1) call CL function
|
||||
console.log(Lisp.fun("format", false, "~R", 123))
|
||||
|
||||
Lisp.apply("qmsg", ["hello from QML"]) // (3) call EQL function
|
||||
// (2) call EQL function
|
||||
Lisp.fun("qmsg", "hello from QML")
|
||||
|
||||
// (3) pass list argument (note Lisp.apply)
|
||||
console.log(Lisp.apply("x:join", [["11", "55"], ":"]))
|
||||
|
||||
// (4) nested list arguments (note Lisp.apply)
|
||||
console.log(Lisp.apply("list", [[[1, 2, 3], ["a", "b", "c"], 4, 5], 6, [[7, 8], 9]]))
|
||||
}
|
||||
|
||||
Text {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue