add trivial "qml-lisp" example (call Lisp from QML); tiny revisions;

This commit is contained in:
polos 2017-01-17 00:06:00 +01:00
parent 75c2b80e4e
commit 0e82b0a517
10 changed files with 123 additions and 3 deletions

View file

@ -0,0 +1,9 @@
A trivial example of calling Lisp functions from QML.
RUN
===
Please run it from this directory.
(For Emacs/Slime, this would be: eql5 ~/slime/eql-start-swank.lisp)

View file

@ -0,0 +1,22 @@
;;; QQuickView loading Lisp enabled QML
#-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))))
;;; QQuickView
(defvar *quick-view* (qnew "QQuickView(QUrl)" (example-url "example.qml")))
(defun run ()
(|setResizeMode| *quick-view* |QQuickView.SizeRootObjectToView|)
(|resize| *quick-view* '(200 100))
(|show| *quick-view*))
(run)

View file

@ -0,0 +1,41 @@
#ifndef LIB_H
#define LIB_H
#include <QtQml>
#include <eql_fun.h>
#ifdef Q_OS_WIN
#define LIB_EXPORT __declspec(dllexport)
#else
#define LIB_EXPORT
#endif
QT_BEGIN_NAMESPACE
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(); }
};
static Lisp* lisp = 0;
static QObject *lisp_provider(QQmlEngine*, QJSEngine*) { return lisp; }
extern "C" {
LIB_EXPORT QObject* ini() {
if(!lisp) {
qmlRegisterSingletonType<Lisp>("EQL5", 1, 0, "Lisp", lisp_provider);
lisp = new Lisp; }
return lisp; }
}
QT_END_NAMESPACE
#endif

View file

@ -0,0 +1,15 @@
QT += qml
TEMPLATE = lib
CONFIG += plugin release
INCLUDEPATH += ../../../../../src
LIBS += -L../../../../.. -leql5
DESTDIR = ./
TARGET = qml_lisp
OBJECTS_DIR = ./tmp/
MOC_DIR = ./tmp/
include(../../../../../src/windows.pri)
HEADERS += qml_lisp.h
SOURCES += qml_lisp.cpp

View file

@ -0,0 +1,15 @@
;;; enable QML to call Lisp functions
;;; (requires a C++ plugin, see "lib/")
(provide :qml-lisp)
(in-package :eql)
(defvar *qml-lisp* (qload-c++ "lib/qml_lisp"))
(defun qml-apply (function arguments)
(let ((value (apply (intern (string-upcase function)) arguments)))
(if (stringp value)
value
(princ-to-string value))))

View file

@ -0,0 +1,18 @@
import QtQuick 2.0
import EQL5 1.0
Item {
id: root
Component.onCompleted: {
console.log(Lisp.apply("format", [null, "~R", 123])) // call CL function
Lisp.apply("qmsg", ["hello from QML"]) // call EQL function
}
Text {
anchors.centerIn: parent
color: "blue"
text: "Lisp enabled QML"
}
}

View file

@ -8,7 +8,7 @@ TARGET = webkit_bridge
OBJECTS_DIR = ./tmp/
MOC_DIR = ./tmp/
macx:QT += network phonon
macx:QT += network
include(../../../../../src/windows.pri)

View file

@ -8,7 +8,7 @@ TARGET = webkit_bridge
OBJECTS_DIR = ./tmp/
MOC_DIR = ./tmp/
macx:QT += network phonon
macx:QT += network
include(../../../../../src/windows.pri)

View file

@ -8,7 +8,7 @@ TARGET = webkit_bridge
OBJECTS_DIR = ./tmp/
MOC_DIR = ./tmp/
macx:QT += network phonon
macx:QT += network
include(../../../../src/windows.pri)