From e09778b76c7760c2e3968da935f8de229c6f0457 Mon Sep 17 00:00:00 2001 From: "pls.153" Date: Sat, 22 Jan 2022 21:56:51 +0100 Subject: [PATCH] fix cpp-lib example for Slime --- cpp-lib/readme.md | 8 ++++---- cpp-lib/run.lisp | 3 ++- slime/readme.md | 1 + src/cpp/main.cpp | 4 +++- src/lisp/ini.lisp | 48 +++++++++++++++++++++++------------------------ 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/cpp-lib/readme.md b/cpp-lib/readme.md index 0705cb9..77a10a8 100644 --- a/cpp-lib/readme.md +++ b/cpp-lib/readme.md @@ -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 ``` diff --git a/cpp-lib/run.lisp b/cpp-lib/run.lisp index 13f3181..f856759 100644 --- a/cpp-lib/run.lisp +++ b/cpp-lib/run.lisp @@ -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)))))) diff --git a/slime/readme.md b/slime/readme.md index aadde0b..495f2f1 100644 --- a/slime/readme.md +++ b/slime/readme.md @@ -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. diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index 686b31c..234cbd0 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -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; } diff --git a/src/lisp/ini.lisp b/src/lisp/ini.lisp index 187a357..42d25cd 100644 --- a/src/lisp/ini.lisp +++ b/src/lisp/ini.lisp @@ -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