Embeding python in Vala
Asked Answered
W

0

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].

Windsail answered 29/5, 2013 at 3:36 Comment(8)
I'm a little confused here. What's lead you to believe that GObject can be automatically marshalled to a Python object?Seneschal
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 programWindsail
This sounds more like a PyGObject question than a Python question.Seneschal
As I've investigated more, I've been coming to the same conclusion. I added the pygobject tag to reflect that.Windsail
Why not just use libpeas?Cryptocrystalline
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?Windsail
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.Seneschal
@Windsail Did you finally find a solution?Deflected

© 2022 - 2024 — McMap. All rights reserved.