Vala Reference Manual [Draft]

Overview

Vala is a new programming language that aims to bring modern language features to GNOME developers without imposing any additional runtime requirements and without using a different ABI than applications and libraries written in C. It provides concise a concise way of using GLib and GObject features, but does not attempt to expose all possibilities. In particular, Vala is primarily a statically typed language - this is a design decision, not an oversight.

The only support that Vala applications require at runtime are the standard GLib and GObject libraries. It is possible to use any system library from Vala, provided that a VAPI file is written to describe the interface - Vala is distributed with VAPI descriptions of most libraries commonly used by GNOME applications, and many others as well.

Vala provides easy integration with DBus, by automatically writing boiler plate code where required, for exposing objects, dispatching methods, etc.

Getting started

The classic "Hello, world" example in Vala:

using GLib;

public class Sample : Object {
	public Sample () {
	}

	public void run () {
		stdout.printf ("Hello, world!\n");
	}

	static int main (string[] args) {
		var sample = new Sample ();
		sample.run ();
		return 0;
	}
}

Store the code in a file whose name ends in ".vala", such as hello.vala, and compile it with the command:

valac -o hello hello.vala

This will produce an executable file called hello. "valac" is the Vala compiler; it will also allow you to take more control of the compile and link processes when required, but that is outside the scope of this introductory section.

Documentation conventions

A large amount of this documentation describes the language features precisely using a simple rule notation. The same notation is used to describe language syntax and semantics, with the accompanying text always explaining what is described. The following example shows the form:

rule-name: literalstring1 literalstring2 [ optional-section ] optional-section: literalstring3

Here, "rule-name" and "optional-section" describe rules, each of which can be expanded in a particular way. Expanding a rule means substituting one of the options of the rule into the place the rule is used. In the example, "optional-section" can be expanded into "literalstring3" or, in "rule-name", "optional-section" can also be substituted for nothing, as it is declared optional by the square brackets. Wherever "rule-name" is required, it can be substituted for either of the options declared in "rule-name". Anything highlighted, such as all "literalstring"s here are not rules, and cannot be expanded.

Example code is shown as follows. Example code will always be valid Vala code, but will not necessarily be usable out of context.

class MyClass : Object {
	int field = 1;
}

Some phrases are used in a specific ways in this documentation and it is often useful to recognise their precise meanings: