Re: [Vala] Upcoming changes in object construction syntax
- From: "Cayle Graumann" <cayle graumann gmail com>
- To: "Jürg Billeter" <j bitron ch>
- Cc: vala paldo org
- Subject: Re: [Vala] Upcoming changes in object construction syntax
- Date: Sat, 10 Mar 2007 00:19:00 -0600
Jurg,
I'm having a hard time with the new creation syntax in vapi
files. As of revision 228, It looks like the compiler is ignoring any
[CCode] directives when it sees a creation method definition .
You can see this with the String.sized method in glib-2.0.vala
Inside of vapi/glib-2.0.vala (line 1197)
[CCode (cname = "g_string_sized_new")]
public String.sized (ulong dfl_size);
However when you use this function like so
var line = new String.sized(1024);
The compiler generates:
GString* line = g_string_new_sized (1024);
instead of
GString* line = g_string_sized_new (1024);
Cayle in Missouri.
On 3/3/07, Jürg Billeter <j bitron ch> wrote:
Hi,
just a heads up that we're about to change some parts of the Vala syntax
regarding object construction. The new syntax should be more reasoned
and follow the GObject type system more closely.
It will get a bit harder to follow development of valac in SVN while
we're adapting the new syntax. We'll release a new version when the
breaking changes are done.
/**
* Example Class to explain the new object construction syntax
*/
public class Maman.Bar {
/**
* Properties
* use construct only if the property needs to be set
* before the constructor gets executed
*/
public int x { get; set construct; }
public int y { get; set construct; }
public string title { get; set; }
private int x_y;
/**
* Creation Method
* corresponds to maman_bar_new in C
* runs first
* you may only set properties here
* properties corresponding to parameters declared with
* construct will automatically be set to the argument
*/
public Bar (construct int x, construct int y) {
}
/**
* Named Creation Method
* corresponds to maman_bar_new_with_title in C
*/
public Bar.with_title (construct string title) {
}
/**
* Constructor
* runs after the construct properties have been set
* often not necessary
*/
construct {
x_y = x + y;
}
static int main (string[] args) {
/* you may set additional properties by name after the
* positional arguments */
var bar = new Bar.with_title ("Hello", x = 10);
return 0;
}
}
Migration of existing code:
* Use new creation method syntax
public construct [with_foo] (...) {...}
=>
public Bar[.with_foo] (...) {...}
* Ensure that you don't do anything in the body of creation methods
except setting properties.
* Use new constructor syntax
Bar () {...}
=>
construct {...}
Regards,
Jürg
_______________________________________________
Vala mailing list
Vala paldo org
http://www.paldo.org/mailman/listinfo/vala
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]