Re: [Vala] Is there an Any type in vala?



Yes it will be much better.

But what about the set_data_full? Some other modifiers shall be
invented?

The following will be much more direct than the cname stuff, and more
flexible(I'll be more specific on CCodeFunc in next mail):

[CCodeFunc g_object_set_data_full(this, key, data, G.DestroyFunc) ]
public void set_data<G> (string key, G# data);

[CCodeFunc g_object_set_data(this, key, data) ]
public void set_data<weak G> (string key, G data);

class SomeClass {
[CCodeFunc g_object_unref(this)]
   public DestroyFunc();
};

Three use case:

1: Use vala auto mem management:
  set_data<SomeClass>("data", new SomeClass());

2: Use vala auto mem management but no ownership transfer:
  set_data<weak SomeClass>("data", new SomeClass());

3: manual management:
  set_data_full<weak SomeClass>("data", new SomeClass(),
SomeClass.DestroyFunc);


Yu
On Sat, 2008-05-17 at 19:21 +0200, Jürg Billeter wrote:
On Sun, 2008-05-11 at 03:39 -0400, Yu Feng wrote:
The need for an 'Any' type emerges in the following context:


Object o = new Object();
Object o1 = new Object();
string s = "string"
o.set_data("data", o1);
o.set_data("string", s);

set_data is currently declared as 
set_data(string, void *);

We should bind g_object_set_data as a generic method

[CCode (cname = "g_object_set_data_full")]
public void set_data<G> (string key, G# data);

However, we don't support generic methods in Vala, yet.

Jürg





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