6

I want to embed the Python interpreter into a program written in Vala to allow for some runtime scripting. I can run parts of my vala code from Python using Introspection, and I've found a rudimentary example of embedding the interpreter in Python here: https://gist.github.com/astagi/1282808.

That example does not show how to pass an instance of an object in Vala to the interpreter and back. In the example of how to embed Python (http://docs.python.org/3/extending/embedding.html#pure-embedding) a variable of type long is converted to/form the python type using using something like this:

PyObject *pvalue = PyLong_FromLong(foo);

and

long foo=PyLong_asLong(pvalue);

The question is what are the equivalent functions for a variable in Vala of type GLib.Object [a GObject in C form].

ajg144
  • 61
  • 2
  • I'm a little confused here. What's lead you to believe that GObject can be automatically marshalled to a Python object? – MrEricSir May 29 '13 at 19:32
  • Here's my reasoning so far: I can write a class called `SomeClass` in Vala that inherits from GObject. I can compile SomeClass to a shared library, and import that to python using `from gi.repository import SomeClass`. When SomeClass is instantiated in python, the resulting object is actually a GObject, wrapped in a PyObject (is that incorrect?). With the python interpreter embed in a Vala program, the user might run a python script that creates an instance of SomeClass `sc=SomeClass()` but its a PyObject managed by the interpreter. How do I get the GObject in `sc` back to main program – ajg144 May 30 '13 at 01:59
  • This sounds more like a PyGObject question than a Python question. – MrEricSir May 30 '13 at 02:13
  • As I've investigated more, I've been coming to the same conclusion. I added the pygobject tag to reflect that. – ajg144 May 30 '13 at 02:58
  • 3
    Why not just use libpeas? – nemequ May 31 '13 at 00:03
  • I'm not familiar with libpeas. I'll take a look at it. Can you point me to an example of a project that uses this to implement a python scripting interface to a program written I'm vala? – ajg144 May 31 '13 at 15:01
  • libpeas is a language-agnostic plugin system based on GObject. If that's what you're trying to do it's likely a good fit -- gedit uses libpeas, for example. – MrEricSir Jun 04 '13 at 00:38
  • @ajg144 Did you finally find a solution? – gavr Apr 21 '19 at 02:58

0 Answers0