Re: [Vala] add methods to a compact class from outside the main definition in a VAPI file



Vala doesn't currently support extension methods.  I'm not sure if it
ever will.  There have been some discussions, but TBH I think we all
have some mixed feelings—I know I do.

In Vala, you don't create aliases like you do with typedef in C, you
subclass.  So, you could do something like

        [Compact, CCode (cname = "xcb_connection_t")]
        public class Icccm : Xcb.Icccm { ... }

However, people with an Xcb.Icccm may have to cast to your subclass—once
that's done, it should work as expected (you can call methods of either
class).

The other option is to use static methods.  Remember, you can nest
namespaces, so you can do something like

        namespace Icccm {
          public static void foo (Xcb.Icccm self);
        }


-Evan


On Tue, 2013-12-17 at 23:50 +0100, rastersoft wrote:
Hi all:

I'm working on the XCB VAPI files, and I have a problem. XCB is 
subdivided in several parts: the core X protocol, utility functions and 
extensions.

The core protocol creates a compact class, Connection, which represents 
a xcb_connection_t structure, and all the functions for the XCB core 
protocol are inside as methods of the Connection compact class.

Now I'm starting to implement several extensions and utility functions, 
like ICCCM and Composite. The problem is that they are a collection of 
functions that receives a xcb_connection_t structure as first parameter, 
just like the core protocol ones. That means that they are like methods 
of the Connection class. The problem is that they belongs to a different 
library, which can be compiled or not in a project, so I think that I 
should not add these extension methods inside the Connection class.

So the question is: is possible to create a VAPI file that depends of 
another, and which adds methods to a class defined in that VAPI file?

If it is not possible, is there a way of doing an "alias" of a compact 
class? This is: for the ICCCM methods, define an Icccm compact class 
with a constructor that receives a Connection object, and what it does 
is to create an alias of that Connection object under the type Icccm, so 
all the ICCCM methods whould be inside that compact class.

(I tried to do that with:

     [Compact]
     [CCode (cname = "xcb_connection_t", cprefix = "xcb_icccm_", 
ref_function = "", unref_function = "")]
     public class Icccm {
         [CCode (cname = "xcb_connect")]
         public Icccm (Connection conn) {
             this = conn;
         }
     }

but returned an error)

Thanks.


Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]