Après une version 0.7.7 sans grande nouveauté, La nouvelle version du compilateur Vala, 0.7.8, vient d'être annoncée :
Changes since 0.7.7
- Support constructor chain up to GObject using Object (...).
- Add syntax for string templates.
- Support (!) non-null casts.
- Many bug fixes and binding updates.
Support constructor chain up to GObject using Object (...)
Il s'agit d'une nouvelle syntaxe pour modifier les propriétés d'un objet lors de sa construction.
Avant :
1 2 3 4 5 6 7 8 9 10 11 12
| class MyWindow : Gtk.Window
{
public MyWindow ()
{
this.type = Gtk.WindowType.POPUP;
}
construct
{
// ...
}
} |
Maintenant :
1 2 3 4 5 6 7 8 9 10 11 12
| class MyWindow : Gtk.Window
{
public MyWindow ()
{
Object (type: Gtk.WindowType.POPUP);
}
construct
{
// ...
}
} |
Add syntax for string templates
Il s'agit d'une nouvelle syntaxe pour facilité la substitution des variables dans une chaine de caractères :
1 2 3
| string name = "Vala";
stdout.printf (@"Hello, $name!\n");
stdout.printf (@"2 + 3 = $(2 + 3)\n"); |
Support (!) non-null casts
1 2 3 4 5
| void main ()
{
string? a = "hello";
string b = a;
} |
Ce code ne compile pas avec la vérification strict ('--enable-experimental-non-null') :
error: Assignment: Cannot convert from `string?' to `string'
Il est maintenant possible d'utiliser l'opérateur '(!)' pour forcer la conversion :
1 2 3 4 5
| void main ()
{
string? a = "hello";
string b = (!) a;
} |
Partager