fix cpp-lib example for Slime

This commit is contained in:
pls.153 2022-01-22 21:56:51 +01:00
parent 2e67185cd2
commit e09778b76c
5 changed files with 34 additions and 30 deletions

View file

@ -2,10 +2,11 @@
Build
-----
Switch to `cpp/` and do:
```
qmake lib.pro
make
$ cd cpp
$ qmake lib.pro
$ make
$ cd ..
```
@ -14,7 +15,6 @@ Run
```
$ lqml ~/slime/qml-start-swank.lisp
$ emacs run.lisp
```

View file

@ -2,5 +2,6 @@
(define-qt-wrappers *cpp*)
(print (hello *cpp* '(1 "two" (1.25 #(50 -50 75)))))
;; qrun* needed in Slime (not running on UI thread)
(qrun* (print (hello *cpp* '(1 "two" (1.25 #(50 -50 75))))))

View file

@ -5,3 +5,4 @@ Swank/Slime
Please put `qml-start-swank.lisp` in your `slime/` directory, and `.swank.lisp`
in your home directory.
Remember to always use `(qquit)` or `(qq)` to gracefully exit the Swank server.

View file

@ -1,6 +1,7 @@
#include <QDir>
#include <QGuiApplication>
#include <QTimer>
#include <QRegularExpression>
#include <QQmlEngine>
#include <QQmlFileSelector>
#include <QQuickView>
@ -78,7 +79,8 @@ int main(int argc, char* argv[]) {
}
bool slime = false;
if (arguments.contains("-slime")) {
if (arguments.contains("-slime")
|| (arguments.indexOf(QRegularExpression::fromWildcard(QStringView(QString("*start-swank*.lisp")))) != -1)) {
arguments.removeAll("-slime");
slime = true;
}

View file

@ -103,11 +103,34 @@
(unless (member x '(t nil))
(symbol-name x)))))
(defun qrun-on-ui-thread (function &optional (blocking t))
;; for internal use
(%qrun-on-ui-thread function blocking))
(defvar *gui-thread* mp:*current-process*)
(defmacro qrun-on-ui-thread* (&body body)
;; for internal use
(let ((values (gensym)))
`(if (eql *gui-thread* mp:*current-process*)
,(if (second body)
(cons 'progn body)
(first body))
(let (,values)
(qrun (lambda ()
(setf ,values (multiple-value-list ,(if (second body)
(cons 'progn body)
(first body))))))
(values-list ,values)))))
(defmacro qrun* (&body body) ; alias
`(qrun-on-ui-thread* ,@body))
(defun qfind-children (object &optional object-name class-name)
(%qfind-children object object-name class-name))
(defun qload-c++ (library-name &optional unload)
(%qload-c++ library-name unload))
(qrun* (%qload-c++ library-name unload)))
(defun define-qt-wrappers (qt-library &rest what)
"args: (qt-library &rest what)
@ -165,29 +188,6 @@
x))
arguments))))
(defun qrun-on-ui-thread (function &optional (blocking t))
;; for internal use
(%qrun-on-ui-thread function blocking))
(defvar *gui-thread* mp:*current-process*)
(defmacro qrun-on-ui-thread* (&body body)
;; for internal use
(let ((values (gensym)))
`(if (eql *gui-thread* mp:*current-process*)
,(if (second body)
(cons 'progn body)
(first body))
(let (,values)
(qrun (lambda ()
(setf ,values (multiple-value-list ,(if (second body)
(cons 'progn body)
(first body))))))
(values-list ,values)))))
(defmacro qrun* (&body body) ; alias
`(qrun-on-ui-thread* ,@body))
(defun qquit (&optional (exit-status 0) (kill-all-threads t))
"args: (&optional (exit-status 0) (kill-all-threads t))
alias: qq