GObject Introspection across multiple languages

324 views Asked by At

The Wiki page of the old PyGTK 2.8 binding states that an object properly written in Python

should also be easily usable from C code, or even other language bindings.

But PyGTK is outdated and should be replaced by PyGObject. Is it possible to mix and match languages with the newer introspection-based binding, too? For example, can I write a gobject class in Vala, extend it with Python and use the result in Java?

2

There are 2 answers

2
nemequ On

In theory, yes, it should be possible. In practice, no, not really. Mixing multiple runtimes like that is extremely difficult, and extremely wasteful of resources. If you want your code to be usable in multiple languages you need pretty much need to write it in C or Vala. Or C++ as long as you expose a C API.

The closest thing you're really going to get is something like libpeas, where you create well-defined extension-points, and are then free to implement those extensions in whatever language you choose.

0
grim On

I've written a C based plugin library that does essentially this. It does use GObject Introspection and in theory it is possible. Right now there's C/C++, Python, Lua, and SeedJS all playing together in the same memory space, but I haven't tried to subclass or call anything other than C in the other languages.

Anyways, feel free to tinker if you like. GPlugin