I've written a C library and used vapigen to create the vapis for it. In the generated files there are some properties defined like:
public int index { get; set; }
And the accessor methods (which I use from C and only return the value of the property) duplicating this 'get' and 'set' functionality:
public int get_index ();
public void request_index (int index);
What I want to do is to tell Vala to call my methods when the Vala code gets or sets the properties using the notation:
i = object.index;
object.index = 42;
instead of translating it to a g_object_get
/g_object_set
call as it does right now.
Is there any way to do this?
I've posted this both in vala-devel and vala mailing lists, but no one answered.
Edit: I'm using gobject-introspection and vapigen with autotools to generate the vapi files automatically without worrying about API changes, so redefining the classes in Vala to do this is not an option for me, but I can use gobject-introspection annotations and metadata files.
Edit with solution: The comments in the selected answer contain the solution to my problem, but basically what I did is to use a custom Vala file and skip the used property using the metadata file.
Relevant contents in the metadata file:
MyObject.index skip
And in the custom Vala file:
namespace MyNamespace
{
public class MyObject : GLib.Object
{
public int index
{
owned get;
[CCode (cname = "db_model_request_index")]
set;
}
}
}
Have you tried something like this?
There's more info about Vala properties in the official Vala Tutorial.