[Kde-bindings] Re: Creating Qt bindings for Common Lisp

Luca Fascione lukes at wetafx.co.nz
Mon Jun 6 23:49:04 UTC 2005

Hello Mario,
I'm doing the same for TCL,
feel free to write to me as well, if you feel like it.

I'm saying this because the TCL API is C, so I might help with some details.


Richard Dale wrote:

>Hi Mario 
>On Saturday 04 June 2005 17:15, Mario Tanev wrote:
>>I was referred to you by Alexander Kellett who gave me some advice on
>>writing Qt bindings for Common Lisp, and I would like to ask for some help.
>>I am ussing UFFI (Universal Foreign Function Interface) with Common Lisp,
>>and it can access c-style (i.e. for c++ extern "C") type functions,
>>structs, primitives and pointers. I have looked through the Qt.cpp file
>>with qtruby and smoke.h and am a little bit confused on how to get things
>>started. Since smoke seems undocumented, I am not exactly sure how to
>>interface with it.
>Have a look at the smoke.h header in kdebindings/smoke and the code generated 
>in kdebindings/smoke/qt and kde. It is really based on a bunch of lookup 
>tables, and understanding Smoke involves finding out what the tables are for 
>and how they interelate.
>>For instance I would need the following:
>>1. Accessing a class variable (I suppose the object is a struct when
>>externed "C")
>>2. Creating an object of certain class
>>3. Calling a method of a class (I suppose this is done by passing the state
>>to the method to determine which instance one is referring to)
>>4. Registering a callback function (written in lisp)
>>Note, these questions refer to the c++ glue code that I would write,
>>anything on the lisp side I can figure out myself.
>>I am continuing to read Qt.cpp and I might figure out the answers to some
>>of these questions, but I would appreciate your help.
>The most important thing you need in common lisp is something like 
>method_missing in ruby or #doesNotUnderstand in Smalltalk, that is a 
>catch-all method for a method not implemented by an instance. So you trap the 
>method call in method_missing, and then look up the C++ method in the Smoke 
>runtime. If there is only one C++ method with the name, then you can call it 
>straight away. Otherwise, you need to resolve which method to call based on 
>the number and type of the lisp args passed to it.
>You need to have a table which maps C++ pointers onto the corresponding lisp 
>instances as weak references. Then when a lisp instance is garbage collected 
>it must be removed from the table. Inside a lisp instance you need a means of 
>keeping a pointer to a small struct with details of the C++ instance. If that 
>isn't possible you would need to keep another mapping of lisp instance to C++ 
>instance in the small struct (look for smokeruby_object in qtruby.h).
>If you look at the archives of the kdebindings list, we did discuss a bit 
>about how Smoke works a couple of months ago (ideally subscribe to it). I'll 
>cc this mail to there anyway.
>-- Richard
>Kde-bindings mailing list
>Kde-bindings at kde.org

Luca Fascione
Pipeline Engineer - Weta Digital

+644 388 0142 (x4749) / +64 21 0764 862

More information about the Kde-bindings mailing list