GObject Introspection across multiple languages

2019-08-08 04:05发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-08 04:27

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.

查看更多
做个烂人
3楼-- · 2019-08-08 04:42

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

查看更多
登录 后发表回答