diff --git a/examples/M-modules/quick/qml-lisp/README.txt b/examples/M-modules/quick/qml-lisp/README.txt index b4068c9..111810f 100644 --- a/examples/M-modules/quick/qml-lisp/README.txt +++ b/examples/M-modules/quick/qml-lisp/README.txt @@ -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 diff --git a/examples/M-modules/quick/qml-lisp/example.lisp b/examples/M-modules/quick/qml-lisp/example.lisp index 59d8381..901cf6f 100644 --- a/examples/M-modules/quick/qml-lisp/example.lisp +++ b/examples/M-modules/quick/qml-lisp/example.lisp @@ -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|) diff --git a/examples/M-modules/quick/qml-lisp/lib/qml_lisp.cpp b/examples/M-modules/quick/qml-lisp/lib/qml_lisp.cpp index e69de29..4883324 100644 --- a/examples/M-modules/quick/qml-lisp/lib/qml_lisp.cpp +++ b/examples/M-modules/quick/qml-lisp/lib/qml_lisp.cpp @@ -0,0 +1,48 @@ +#include "qml_lisp.h" +#include + +QT_BEGIN_NAMESPACE + +static Lisp* lisp = 0; + +static QObject* lisp_provider(QQmlEngine*, QJSEngine*) { return lisp; } + +QObject* ini() { + if(!lisp) { + lisp = new Lisp; + qmlRegisterSingletonType("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 diff --git a/examples/M-modules/quick/qml-lisp/lib/qml_lisp.h b/examples/M-modules/quick/qml-lisp/lib/qml_lisp.h index f8c6147..0ed0c41 100644 --- a/examples/M-modules/quick/qml-lisp/lib/qml_lisp.h +++ b/examples/M-modules/quick/qml-lisp/lib/qml_lisp.h @@ -2,7 +2,6 @@ #define LIB_H #include -#include #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("EQL5", 1, 0, "Lisp", lisp_provider); } - return lisp; } -} - QT_END_NAMESPACE #endif diff --git a/examples/M-modules/quick/qml-lisp/qml/example.qml b/examples/M-modules/quick/qml-lisp/qml/example.qml index 6f3a0be..f741704 100644 --- a/examples/M-modules/quick/qml-lisp/qml/example.qml +++ b/examples/M-modules/quick/qml-lisp/qml/example.qml @@ -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 { diff --git a/src/ecl_fun.cpp b/src/ecl_fun.cpp index 08a325f..3b43fd4 100644 --- a/src/ecl_fun.cpp +++ b/src/ecl_fun.cpp @@ -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::ULongLong: l_obj = ecl_make_unsigned_integer(var.toULongLong()); break; // for nested QVariantLists: - case QMetaType::QVariantList: + case QVariant::List: Q_FOREACH(QVariant v, var.value()) { l_obj = CONS(from_qvariant_value(v), l_obj); } l_obj = cl_nreverse(l_obj);