1

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
XZS
  • 2,374
  • 2
  • 19
  • 38

2 Answers2

1

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.

lidaobing
  • 1,005
  • 13
  • 26
nemequ
  • 16,623
  • 1
  • 43
  • 62
  • Well-defined entrypoints are plenty in my case, so libpeas is a good hint. It just seems that it supports not exactly whatever language I choose, but in fact much less languages than Gbject introspection. [Or am I missing something?](http://stackoverflow.com/questions/18633753) – XZS Sep 05 '13 at 14:50
  • libpeas needs to support a language itself, in addition to the language having support for gobject-introspection. For example, libpeas needs to use the Python runtime library to load and execute `.py` files in plugins. gobject-introspection doesn’t provide this: it provides a way for each language runtime to load GIR and typelib files to access the APIs they bind. For Python, for example, this is a Python module which loads the typelib and exposes its classes as Python classes. – Philip Withnall Dec 16 '17 at 21:22
1

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

grim
  • 760
  • 4
  • 13