[Xcb] language bindings for xcb
Thomas Hunger
hto at arcor.de
Thu May 17 15:01:18 PDT 2007
Hello,
the following problem came up when I reactivated my old python
bindings for xcb [1]. It is a more general problem for all
object-oriented bindings.
Each extension (e.g. render) has its own library and header file. To
use it from c one uses pkg-config and the appropiate #include.
In my bindings there is a class "Connection" which connects at
__init__ time. Now I can use the basic functions like this:
>>> import xcb
>>> c = xcb.Connection()
>>> win = c.generate_id()
>>> ...
The connection object in the first example cannot use e.g.
>>> c.render_create_picture(...)
because the connection does not now whether the render extension is
available at all [2]. The module-source would also need all possible
extensions installed at compile time (modules cannot be developed
separatly).
If I follow the c-model for extensions the result would be:
>>> import render
>>> render.create_picture(c, ...)
meaning that the connection is passed as the first argument. The
explicit import ensures that either the render extension module is
available or an exception is thrown. The extension-modules can also
be developed separatly. OTOH this is not very object oriented.
Another possibility would be to override the __new__ method of the
Connection. When __new__ is called it scans for python-xcb-modules
and creates an attribute for each found module. Connection could then
be used like this:
>>> c.render.create_picture(...) # module render exists
After all this the question is: What do you think the api should be
like for object-oriented programming languages?
Tom
[1] I will put them online next week, I am not at home currently.
[2] It is possible to do create additional render_xxx methods for
the connection class after an "import render" statement. This is
not trivial to do from c. I also think that it is not very
intuitive.
More information about the Xcb
mailing list