mirror of
https://gitlab.com/eql/EQL5.git
synced 2025-12-15 14:50:58 -08:00
add trivial "qml-lisp" example (call Lisp from QML); tiny revisions;
This commit is contained in:
parent
75c2b80e4e
commit
0e82b0a517
10 changed files with 123 additions and 3 deletions
9
examples/M-modules/quick/qml-lisp/README.txt
Normal file
9
examples/M-modules/quick/qml-lisp/README.txt
Normal 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)
|
||||
|
||||
22
examples/M-modules/quick/qml-lisp/example.lisp
Normal file
22
examples/M-modules/quick/qml-lisp/example.lisp
Normal 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)
|
||||
0
examples/M-modules/quick/qml-lisp/lib/qml_lisp.cpp
Normal file
0
examples/M-modules/quick/qml-lisp/lib/qml_lisp.cpp
Normal file
41
examples/M-modules/quick/qml-lisp/lib/qml_lisp.h
Normal file
41
examples/M-modules/quick/qml-lisp/lib/qml_lisp.h
Normal 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
|
||||
15
examples/M-modules/quick/qml-lisp/lib/qml_lisp.pro
Normal file
15
examples/M-modules/quick/qml-lisp/lib/qml_lisp.pro
Normal 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
|
||||
|
||||
15
examples/M-modules/quick/qml-lisp/qml-lisp.lisp
Normal file
15
examples/M-modules/quick/qml-lisp/qml-lisp.lisp
Normal 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))))
|
||||
|
||||
18
examples/M-modules/quick/qml-lisp/qml/example.qml
Normal file
18
examples/M-modules/quick/qml-lisp/qml/example.qml
Normal 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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ TARGET = webkit_bridge
|
|||
OBJECTS_DIR = ./tmp/
|
||||
MOC_DIR = ./tmp/
|
||||
|
||||
macx:QT += network phonon
|
||||
macx:QT += network
|
||||
|
||||
include(../../../../../src/windows.pri)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ TARGET = webkit_bridge
|
|||
OBJECTS_DIR = ./tmp/
|
||||
MOC_DIR = ./tmp/
|
||||
|
||||
macx:QT += network phonon
|
||||
macx:QT += network
|
||||
|
||||
include(../../../../../src/windows.pri)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ TARGET = webkit_bridge
|
|||
OBJECTS_DIR = ./tmp/
|
||||
MOC_DIR = ./tmp/
|
||||
|
||||
macx:QT += network phonon
|
||||
macx:QT += network
|
||||
|
||||
include(../../../../src/windows.pri)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue