review "qml-lisp"

This commit is contained in:
polos 2017-01-17 22:28:39 +01:00
parent 03c7a5ded5
commit 140e793040
6 changed files with 77 additions and 29 deletions

View file

@ -5,5 +5,7 @@ RUN
Please run it from this directory. 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

View file

@ -3,16 +3,14 @@
#-qt-wrapper-functions ; see README-OPTIONAL.txt #-qt-wrapper-functions ; see README-OPTIONAL.txt
(load (in-home "src/lisp/all-wrappers")) (load (in-home "src/lisp/all-wrappers"))
(require :qml-lisp "qml-lisp")
(qrequire :quick) (qrequire :quick)
(defun example-url (name) (require :qml-lisp "qml-lisp")
(|fromLocalFile.QUrl| (in-home (x:cc "examples/M-modules/quick/qml-lisp/qml/" name))))
;;; QQuickView ;;; QQuickView
(defvar *quick-view* (qnew "QQuickView(QUrl)" (example-url "example.qml"))) (defvar *quick-view* (qnew "QQuickView(QUrl)"
(|fromLocalFile.QUrl| "qml/example.qml")))
(defun run () (defun run ()
(|setResizeMode| *quick-view* |QQuickView.SizeRootObjectToView|) (|setResizeMode| *quick-view* |QQuickView.SizeRootObjectToView|)

View file

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

View file

@ -2,7 +2,6 @@
#define LIB_H #define LIB_H
#include <QtQml> #include <QtQml>
#include <eql_fun.h>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#define LIB_EXPORT __declspec(dllexport) #define LIB_EXPORT __declspec(dllexport)
@ -12,30 +11,20 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
extern "C" { LIB_EXPORT QObject* ini(); }
class Lisp : public QObject { class Lisp : public QObject {
Q_OBJECT Q_OBJECT
public: public:
Q_INVOKABLE QString apply(const QString& function, const QVariantList& arguments = QVariantList()) { Q_INVOKABLE QString fun(const QString&, // function name plus max. 9 arguments
QVariant ret = const QVariant& = QVariant(), const QVariant& = QVariant(), const QVariant& = QVariant(),
eql_fun("eql::qml-apply", QVariant::String, const QVariant& = QVariant(), const QVariant& = QVariant(), const QVariant& = QVariant(),
Q_ARG(QString, function), const QVariant& = QVariant(), const QVariant& = QVariant(), const QVariant& = QVariant());
Q_ARG(QVariantList, arguments));
return ret.toString(); } 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 QT_END_NAMESPACE
#endif #endif

View file

@ -6,11 +6,22 @@ Item {
Component.onCompleted: { 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 { Text {

View file

@ -1117,7 +1117,7 @@ static cl_object from_qvariant_value(const QVariant& var) {
case QVariant::UInt: l_obj = ecl_make_unsigned_integer(var.toUInt()); break; case QVariant::UInt: l_obj = ecl_make_unsigned_integer(var.toUInt()); break;
case QVariant::ULongLong: l_obj = ecl_make_unsigned_integer(var.toULongLong()); break; case QVariant::ULongLong: l_obj = ecl_make_unsigned_integer(var.toULongLong()); break;
// for nested QVariantLists: // for nested QVariantLists:
case QMetaType::QVariantList: case QVariant::List:
Q_FOREACH(QVariant v, var.value<QVariantList>()) { Q_FOREACH(QVariant v, var.value<QVariantList>()) {
l_obj = CONS(from_qvariant_value(v), l_obj); } l_obj = CONS(from_qvariant_value(v), l_obj); }
l_obj = cl_nreverse(l_obj); l_obj = cl_nreverse(l_obj);