atlas-engineer / cl-webengine

A binding to WebEngine Qt for Common Lisp
BSD 3-Clause "New" or "Revised" License
18 stars 7 forks source link

In order to circumvent this problem, we can write functions in C that call the C++ code that we need. Concretely it looks like this:

In this way, we can now invoke C++ through Lisp. A concrete example is shown below for a single function:

** interface.h

+NAME: interface.h

+BEGIN_SRC C++

extern "C" void widgetShow(void* widget);

+END_SRC

** interface.cpp

+NAME: interface.cpp

+BEGIN_SRC cpp

void widgetShow(void widget) { QWidget _widget = reinterpret_cast<QWidget*>(widget); _widget->show(); }

+END_SRC

** interface.lisp

+NAME: interface.lisp

+BEGIN_SRC lisp

(defcfun ("widgetShow" widget-show) :void (widget :pointer)) (export 'widget-show)

+END_SRC

The library requires Qt5 and Qt5 Webengine. More specifically, you don't need all of Qt5, the following Qt5 components are enough:

After compiling, you will need to copy the shared libraries to a location where CFFI can find them. If you need to append a location for CFFI, you can add the following lines to your Lisp initialization:

+NAME: sbclrc

+BEGIN_SRC lisp

(ql:quickload :cffi) (pushnew "/opt/local/lib/" cffi:foreign-library-directories :test #'equal)

+END_SRC

The above demonstrates an example in SBCL, where the location of the shared library will be in =/opt/local/lib=.