mirror of
https://gitlab.com/eql/lqml.git
synced 2026-01-09 18:51:32 -08:00
make example work on android; revisions
This commit is contained in:
parent
113386fdae
commit
99ea5a081d
49 changed files with 637 additions and 133 deletions
|
|
@ -214,7 +214,7 @@ cl_object qload_cpp(cl_object l_lib_name, cl_object l_unload) { /// qload-c++
|
|||
/// The plugin will be reloaded (if supported by the OS) every time you call
|
||||
/// this function. If the UNLOAD argument is not NIL, the plugin will be
|
||||
/// unloaded (if supported by the OS).
|
||||
/// N.B: This works only for Qt6 functions with the following signature:
|
||||
/// N.B: This works only for Qt functions with the following signature:
|
||||
/// "QVariant foo(QVariant, ...)" ; max 10 QVariant arguments
|
||||
/// Since a QVariant can also be of type QVariantList, this is a perfect fit
|
||||
/// for (nested) Lisp lists.
|
||||
|
|
@ -348,7 +348,7 @@ cl_object qsingle_shot2(cl_object l_msec, cl_object l_fun) {
|
|||
/// (qsingle-shot 1000 'one-second-later)
|
||||
ecl_process_env()->nvalues = 1;
|
||||
if (l_fun != ECL_NIL) {
|
||||
new SingleShot(toInt(l_msec), l_fun);
|
||||
new SingleShot(toInt(l_msec), l_fun); // see 'deleteLater()' in sources
|
||||
return l_msec;
|
||||
}
|
||||
error_msg("QSINGLE-SHOT", LIST2(l_msec, l_fun));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef ECL_EXT_H
|
||||
#define ECL_EXT_H
|
||||
|
||||
#undef SLOT
|
||||
|
||||
#include <ecl/ecl.h>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
|
|
@ -8,7 +10,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#define DEFUN(name, c_name, num_args) \
|
||||
ecl_def_c_function(ecl_read_from_cstring(name), (cl_objectfn_fixed)c_name, num_args);
|
||||
ecl_def_c_function(ecl_read_from_cstring(name), (cl_objectfn_fixed)c_name, num_args);
|
||||
|
||||
#define STRING(s) ecl_make_constant_base_string(s, -1)
|
||||
|
||||
|
|
@ -19,12 +21,12 @@ QT_BEGIN_NAMESPACE
|
|||
#define TERPRI() cl_terpri(0)
|
||||
|
||||
#define STATIC_SYMBOL(var, name) \
|
||||
static cl_object var = cl_intern(1, ecl_make_constant_base_string(name, -1));
|
||||
static cl_object var = cl_intern(1, ecl_make_constant_base_string(name, -1));
|
||||
|
||||
#define STATIC_SYMBOL_PKG(var, name, pkg) \
|
||||
static cl_object var = cl_intern(2, \
|
||||
ecl_make_constant_base_string(name, -1), \
|
||||
cl_find_package(ecl_make_constant_base_string(pkg, -1)));
|
||||
static cl_object var = cl_intern(2, \
|
||||
ecl_make_constant_base_string(name, -1), \
|
||||
cl_find_package(ecl_make_constant_base_string(pkg, -1)));
|
||||
|
||||
#define LEN(x) fixint(cl_length(x))
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
|
||||
const char LQML::version[] = "22.1.1"; // Jan 2022
|
||||
const char LQML::version[] = "22.2.1"; // Feb 2022
|
||||
|
||||
extern "C" void ini_LQML(cl_object);
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ static void logMessageHandler(QtMsgType, const QMessageLogContext& context, cons
|
|||
report += " function ";
|
||||
report += QString(context.function);
|
||||
}
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "[EQL5]", report.toLocal8Bit().constData());
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "[LQML]", report.toLocal8Bit().constData());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -44,11 +44,12 @@ LQML::LQML(int argc, char* argv[], QQuickView* view) : QObject() {
|
|||
qInstallMessageHandler(logMessageHandler); // see above
|
||||
#endif
|
||||
if (!cl_booted_p) {
|
||||
cl_boot(argc, argv); }
|
||||
cl_boot(argc, argv);
|
||||
}
|
||||
iniCLFunctions();
|
||||
ecl_init_module(NULL, ini_LQML);
|
||||
eval("(in-package :qml-user)");
|
||||
eval(QString("(setf *quick-view* (qt-object %1))")
|
||||
eval(QString("(setf qml:*quick-view* (qml:qt-object %1))")
|
||||
.arg(reinterpret_cast<quintptr>(view)));
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +88,7 @@ void LQML::eval(const QString& lisp_code, bool slime) {
|
|||
safe_eval_debug(lisp_code.toLatin1().constData());
|
||||
} else {
|
||||
cl_object ret = safe_eval(lisp_code.toLatin1().constData());
|
||||
if (ecl_t_of(ret) == t_fixnum && (fix(ret) == EVAL_ERROR_VALUE)) {
|
||||
if ((ecl_t_of(ret) == t_fixnum) && (fix(ret) == EVAL_ERROR_VALUE)) {
|
||||
qDebug() << "Error evaluating " << lisp_code;
|
||||
exit(-1);
|
||||
}
|
||||
|
|
@ -96,7 +97,7 @@ void LQML::eval(const QString& lisp_code, bool slime) {
|
|||
|
||||
void LQML::ignoreIOStreams() {
|
||||
// [Windows] print output would cause a gui exe to crash (without console)
|
||||
eval("(eql::ignore-io-streams)");
|
||||
eval("(qml::ignore-io-streams)");
|
||||
}
|
||||
|
||||
void LQML::exec(lisp_ini ini, const QByteArray& expression, const QByteArray& package) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef LQML_H
|
||||
#define LQML_H
|
||||
|
||||
#undef SLOT
|
||||
|
||||
#include <ecl/ecl.h>
|
||||
#include <QObject>
|
||||
#include <QByteArray>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@
|
|||
#define ADD_MACOS_BUNDLE_IMPORT_PATH
|
||||
#endif
|
||||
|
||||
#ifdef INI_LISP
|
||||
extern "C" void ini_app(cl_object);
|
||||
#endif
|
||||
|
||||
int catch_all_qexec() {
|
||||
int ret = 0;
|
||||
CL_CATCH_ALL_BEGIN(ecl_process_env()) {
|
||||
|
|
@ -25,6 +29,7 @@ int catch_all_qexec() {
|
|||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QGuiApplication app(argc, argv);
|
||||
//app.setOrganizationName("MyProject");
|
||||
//app.setOrganizationDomain("my.org");
|
||||
|
|
@ -49,25 +54,26 @@ int main(int argc, char* argv[]) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
#ifdef INI_LISP
|
||||
ecl_init_module(NULL, ini_app);
|
||||
#endif
|
||||
|
||||
new QQmlFileSelector(view.engine(), &view);
|
||||
QString qml("qml/main.qml");
|
||||
QUrl url("qrc:///" + qml); // (1) try resources first (final app)
|
||||
bool set = false;
|
||||
if (QFile::exists(url.fileName())) {
|
||||
set = true;
|
||||
QUrl url;
|
||||
if (QFile::exists(qml)) { // (1) try local file (development)
|
||||
url = QUrl::fromLocalFile(qml);
|
||||
} else {
|
||||
url = QUrl::fromLocalFile(qml); // (2) use local file (development)
|
||||
if (QFile::exists(QDir::currentPath() + "/" + qml)) {
|
||||
set = true;
|
||||
}
|
||||
url = QUrl("qrc:///" + qml); // (2) use resource file (final app)
|
||||
}
|
||||
if (set) {
|
||||
view.setSource(url);
|
||||
if (view.status() == QQuickView::Error) {
|
||||
return -1;
|
||||
}
|
||||
view.setSource(url);
|
||||
if (view.status() != QQuickView::Error) {
|
||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||
#if (defined Q_OS_ANDROID) || (defined Q_OS_IOS)
|
||||
view.show();
|
||||
#else
|
||||
QTimer::singleShot(0, &view, &QQuickView::show);
|
||||
#endif
|
||||
}
|
||||
|
||||
// load .eclrc
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "marshal.h"
|
||||
#include <ecl/ecl.h>
|
||||
#include <QVariant>
|
||||
#include <QObject>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef MARSHAL_H
|
||||
#define MARSHAL_H
|
||||
|
||||
#undef SLOT
|
||||
|
||||
#include <ecl/ecl.h>
|
||||
#include <QRectF>
|
||||
#include <QVariant>
|
||||
|
|
@ -12,12 +14,12 @@ QT_BEGIN_NAMESPACE
|
|||
#define STRING_COPY(s) (s ? ecl_make_simple_base_string(s, -1) : ECL_NIL)
|
||||
|
||||
#define STATIC_SYMBOL(var, name) \
|
||||
static cl_object var = cl_intern(1, ecl_make_constant_base_string(name, -1));
|
||||
static cl_object var = cl_intern(1, ecl_make_constant_base_string(name, -1));
|
||||
|
||||
#define STATIC_SYMBOL_PKG(var, name, pkg) \
|
||||
static cl_object var = cl_intern(2, \
|
||||
ecl_make_constant_base_string(name, -1), \
|
||||
cl_find_package(ecl_make_constant_base_string(pkg, -1)));
|
||||
static cl_object var = cl_intern(2, \
|
||||
ecl_make_constant_base_string(name, -1), \
|
||||
cl_find_package(ecl_make_constant_base_string(pkg, -1)));
|
||||
|
||||
#define LEN(x) fixint(cl_length(x))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "qt_ecl.h"
|
||||
#include "marshal.h"
|
||||
#include "ecl_ext.h"
|
||||
#include <ecl/ecl.h>
|
||||
#include <QVariant>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
|
|||
25
src/cpp/single_shot.cpp
Normal file
25
src/cpp/single_shot.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "single_shot.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
SingleShot::SingleShot(int msec, void* fun)
|
||||
: function(fun) {
|
||||
id = startTimer(msec);
|
||||
}
|
||||
|
||||
void SingleShot::timerEvent(QTimerEvent*) {
|
||||
killTimer(id);
|
||||
const cl_env_ptr l_env = ecl_process_env();
|
||||
CL_CATCH_ALL_BEGIN(l_env) {
|
||||
CL_UNWIND_PROTECT_BEGIN(l_env) {
|
||||
cl_funcall(1, (cl_object)function);
|
||||
}
|
||||
CL_UNWIND_PROTECT_EXIT {}
|
||||
CL_UNWIND_PROTECT_END;
|
||||
}
|
||||
CL_CATCH_ALL_END;
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
|
@ -1,30 +1,24 @@
|
|||
#ifndef SINGLE_SHOT_H
|
||||
#define SINGLE_SHOT_H
|
||||
|
||||
#undef SLOT
|
||||
|
||||
#include <ecl/ecl.h>
|
||||
#include <QObject>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
struct SingleShot : public QObject {
|
||||
class SingleShot : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
int id;
|
||||
void* function;
|
||||
|
||||
SingleShot(int msec, void* fun) : id(startTimer(msec)), function(fun) {}
|
||||
SingleShot(int, void*);
|
||||
|
||||
void timerEvent(QTimerEvent*) {
|
||||
killTimer(id);
|
||||
const cl_env_ptr l_env = ecl_process_env();
|
||||
CL_CATCH_ALL_BEGIN(l_env) {
|
||||
CL_UNWIND_PROTECT_BEGIN(l_env) {
|
||||
cl_funcall(1, (cl_object)function);
|
||||
}
|
||||
CL_UNWIND_PROTECT_EXIT {}
|
||||
CL_UNWIND_PROTECT_END;
|
||||
}
|
||||
CL_CATCH_ALL_END;
|
||||
delete this;
|
||||
}
|
||||
protected:
|
||||
void timerEvent(QTimerEvent*) override;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue