[Ecls-list] Handling C/C++ pointers in lisp code (Was "can't compile with g++")

Larry Clapp larry at theclapp.org
Mon Mar 1 06:11:04 UTC 2004


Juan Jose Garcia-Ripoll said:
> On Monday 01 March 2004 03:57, Larry Clapp wrote:
>> I've set C:*CC* to "g++", and also diddled a bit with
>> C::*CC-FLAGS*.  The compile line looks like
>
> Have you compiled your ECL with the flag --enable-cxx???

No, oops.

>> I have some sample code that looks like
>>
>>     (clines "#include \"cxx-ffi-test.h\"")
>>
>>     (defvar *a*
>> 	(c-inline () () :int
>> 	    "(int) new foo()"
>>
>> 	    :one-liner t))
>>
>>     (defun make-foo ()
>>       (c-inline () () :int
>> 	    "(int) new foo()"
>>
>> 	    :one-liner t))
>>
>>     (defun |foo::bar| (a-foo)
>>       (c-inline (a-foo) (:int) :int
>> 	    "((foo *) #0)->bar()"
>>
>> 	    :one-liner t))
>>
>>     ; which all works fine, until ...
>>
>>     (defclass baz ()
>>       ((slot)))
>
> But you know that lisp and C++ classes are not compatible *puzzled*

Well, I hope to do something along the lines of

    ; typed in my mailer, from memory; please forgive any syntax
    ; errors

    (defclass c++-object ()
      ((this :accessor this :type <pointer-to-c++-object>)))

    (defclass c++-base-class (c++-object)
      ())

    (defclass c++-child (c++-base-class)
      ())

    ; ... and so on, replicating the C++ class hierarchy in the
    ; library I want to use (Qt)

    (defmethod allocate-c++-instance ((obj c++-object))
      (setf (this obj)
	    (c-lines (???) (???) :???
		     "new cxx_object(???)"
		     :one-liner t)))

    (defmethod allocate-c++-instance ((obj c++-child))
      (setf (this obj)
	    (c-lines (???) (???) :???
		     "new cxx_child(???)"
		     :one-liner t)))

    ; ... and so on ...

    (defmethod initialize-instance :after ((obj c++-object)
					   &key)
      (allocate-c++-instance obj))

which I hope will allow me to use Qt on my Zaurus in a fairly Lispy manner.

> What is then the "baz" thing for?

The baz thing was unrelated to the previous code, and I put it in solely
to exhibit the problem with the "clos_ensure_class()" prototype.  Without
a Lisp class, clos_ensure_class didn't show up in the .h file.  Sorry for
any confusion.

> The ECL implementation of UFFI is ongoing work, but in the meantime I
> would suggest you to do something like...
[snip example of ecl_make_foreign]

Thanks!

> Ouch, before I forget it, to get the FFI objects you have to
> compile with --with-ffi.

Okay.  Recompile using -with-cxx and -with-ffi.  Will do.

-- Larry





More information about the ecl-devel mailing list