[Kde-bindings] The Magic of Smoke

Richard Dale rdale at foton.es
Thu Oct 19 17:10:02 UTC 2006


On Thursday 19 October 2006 17:14, Paulo J. Matos wrote:
> Hi all,
>
> I've been looking to smoke, and the interface not only through
> qt4-ruby but also from the _only_, afaik, tutorial online (if you can
> consider it as such). Smoke seems like magic... it seems to work but I
> can't understand why.
>
> Hope someone is able to answer these questions or point me to the
> answers (a nice 'gift') would definitely be a reference manual for
> it...
> - Why do I need to create a binding class? If the answer is : "to
> define the abstract functions", then why are those 3 functions
> abstract? What are they for and why are not defined by default?

    virtual void deleted(Smoke::Index classId, void *obj) = 0;

This method is called by the c++ destructor of an instance in the smoke lib. 
You provide you own version of deleted() so you can clean up things like 
entries in a table that maps the C++ instance to the corresponding instance 
in the bindings language, or to mark the instance as already deleted so that 
when the bindings instance is garbage collected the c++ instance won't be 
deleted twice.

    virtual bool callMethod(Smoke::Index method, void *obj, Smoke::Stack args, 
bool isAbstract = false) = 0;

You implement callMethod() to handle virtual method callbacks using 
marshallers to and from C++ to the bindings language. This allows you to 
override any virtual method in the Smoke library with a version written in 
the bindings language.

    virtual char* className(Smoke::Index classId) = 0;

The class name used in the bindings language might be different from the one 
used in the original C++. For instance, in QtRuby and PerlQt 'QWidget' is 
named as 'Qt::Widget', and the className() method provides a bindings 
specific version of the class name.

> Answering to these questions initially would already be pretty nice,
> still I have one more.
>
> Qt4 uses qmake! How can I generate a qmake file to compile some code
> with smoke lib, all the libs from Qt and generate a shared lib?
Well qmake is pretty easy to use. You can start with a 'qmake -project' 
command to generate a .pro file based on the files it finds in the current 
directory. Then add any extra libs you need by hand. Search for .pro files in 
the qtruby project if you want to see examples.

-- Richard



More information about the Kde-bindings mailing list