Methods

C++ methods are generic functions in the :cxx package.

The C++ method call: myInstance->frob(1); is in Lisp:

(frob my-instance 1)

Overload Resolution

C++ style overload resolution with conversion sequences is supported. For example this:

(cxx:set-pen (make-instance 'qt:painter) (make-instance 'qt:color :args '("green")))

is equivalent to:

(cxx:set-pen (make-instance 'qt:painter) "green")

In the second case a temporary qt:color instance is implicitly created.

Setter Methods

Instead of calling a setter method that takes no additional arguments,

(cxx:set-object-name (make-instance 'qt:object) "foo")

you can use its setfable getter.

(setf (cxx:object-name (make-instance 'qt:object)) "foo")

defmethod

You can extend the :cxx generic functions by adding methods. :around, :before, :after and (call-next-method) are supported.

(defclass the-object-does-nothing (qt:object)
  ()
  (:metaclass cxx:class))

(defmethod cxx:timer-event ((object the-object-does-nothing) event)
  (declare (ignore object event))
  (call-next-method))

:cxx generic functions can be overload by argument count. Lambda list keywords (e.g.: &rest and &key) are not supported.

Note

Make sure you have the right number of arguments when adding a method; otherwise it will not be called.

Caution

The arguments of the method might have dynamic extend; i.e.: they are only valid in the body of the method.

Condition

Unwinding of the C++ stack is not supported. This means that you must not invoke a restart that skips any foreign function. You will most likely encounter this problem when an error is signaled in a virtual method you have overwritten. [3]. For this case restarts are provide that allow to return a value for the failed method, call the default C++ implementation instead (something like #'call-next-method) or retry.

Operators

Instead of using the various cxx:operator methods you can use their Lisp equivalent in the :cxx package.

cxx:>cxx:>=  

cxx:=cxx:/=  

cxx:<=cxx:<  

cxx:+cxx:-cxx:*cxx:/
cxx:1+cxx:1-  

cxx:incfcxx:decf  

cxx:aref



[3] For example an event handler that is called from the C++ library.