wrapping a non-qt c++ class

59 views
Skip to first unread message

Martin DeMello

unread,
Jan 6, 2013, 2:10:18 AM1/6/13
to eql-...@googlegroups.com
I have an eql application that I'm writing using the my_app template
from the source tree, with most of the code in lisp. Can I link in and
use a C++ class from an external library? And if so, could someone
provide a small example?

martin

Polos Ruetz

unread,
Jan 6, 2013, 10:24:44 AM1/6/13
to eql-...@googlegroups.com
2013/1/6, Martin DeMello <martin...@gmail.com>:
Did you see this thread from the ECL mailing list?

http://sourceforge.net/mailarchive/message.php?msg_id=30195364

Paul

Martin DeMello

unread,
Jan 6, 2013, 10:23:59 PM1/6/13
to eql-...@googlegroups.com
Thanks, didn't manage to find that. It looks a bit more involved than
I had imagined - I might just go the C wrapper route instead.

martin

polos

unread,
Jan 7, 2013, 5:38:30 AM1/7/13
to eql-...@googlegroups.com
On Monday, January 7, 2013 4:23:59 AM UTC+1, Martin DeMello wrote:
Thanks, didn't manage to find that. It looks a bit more involved than
I had imagined - I might just go the C wrapper route instead.

Just another idea: if you already use a wrapper, you could wrap your C++ class in QObject, and go with "Qt_EQL_dynamic/", using QFUN+ / Q_INVOKABLE and friends.

(I have not done this, but I imagine that probably the Qt types/classes would fit better than the C types).

Paul

Martin DeMello

unread,
Jan 7, 2013, 7:08:32 AM1/7/13
to eql-...@googlegroups.com
Hm - let me describe my problem a bit more. I'm completely new to ecl
(and indeed to common lisp) so i could be missing something obvious in
the way i'm trying to approach this.

I'm trying to convert the following C program:
https://github.com/martindemello/arcccc/blob/master/src/arccc.c into a
library I can call from eql. I'm thinking a C++ class would be the
best way to go about it, because there's a lot of internal state, both
defined in main() and passed around, and stored in static global
variables, and if I want to change the program from "spit out all
solutions" to "act as a generator and return the next solution every
time 'next' is called" it would be neater to encapsulate that state in
a class.

The interface I'll need to the class is pretty simple, though:

solver = new Solver(dictionary);
solver.init(grid)
new_grid = solver.next_solution()

and of course I'll need a way to convert `grid` to and from a lisp
array to a char[][] (which the ECL docs should be able to help with).
So, from the discussion you pointed me to, it looks like a C wrapper
and FFI:C-INLINE is definitely an option. By "Wrap my C++ class in
QObject" do you mean write a new class that inherits from QObject,
holds a pointer to my class, and implements signals and slots that
call its methods?

martin

polos

unread,
Jan 7, 2013, 7:57:20 AM1/7/13
to eql-...@googlegroups.com
On Monday, January 7, 2013 1:08:32 PM UTC+1, Martin DeMello wrote:
The interface I'll need to the class is pretty simple, though:

solver = new Solver(dictionary);
solver.init(grid)
new_grid = solver.next_solution()

ok this is simple enough, and not worth using a QObject wrapper.

(Just a hint: if your grid is not huge, you could construct a string in C representing a Lisp array, and then read it in Lisp using READ-FROM-STRING.)
 
By "Wrap my C++ class in
QObject" do you mean write a new class that inherits from QObject,
holds a pointer to my class, and implements signals and slots that
call its methods?
 
yes, as in Qt you can use convenient classes like QStringList, QList<int>, QVariantList etc., but in your case this seems not necessary.

Paul
Reply all
Reply to author
Forward
0 new messages