Debian Codegraph @

test/syntax/source/code/vala

raw
1 using DBus;
2
3 namespace Test {
4 class Foo : Object {
5 public signal void some_event (); // definition of the signal
6 public void method () {
7 some_event (); // emitting the signal (callbacks get invoked)
8 }
9 }
10 }
11
12 /* defining a class */
13 class Track : GLib.Object, Test.Foo { /* subclassing 'GLib.Object' */
14 public double mass; /* a public field */
15 public double name { get; set; } /* a public property */
16 private bool terminated = false; /* a private field */
17 public void terminate() { /* a public method */
18 terminated = true;
19 }
20 }
21
22 const ALL_UPPER_CASE = "you should follow this convention";
23
24 var t = new Track(); // same as: Track t = new Track();
25 var s = "hello"; // same as: string s = "hello";
26 var l = new List<int>(); // same as: List<int> l = new List<int>();
27 var i = 10; // same as: int i = 10;
28
29
30 #if (ololo)
31 Regex regex = /foo/;
32 #endif
33
34 /*
35 * Entry point can be outside class
36 */
37 void main () {
38 var long_string = """
39 Example of "verbatim string".
40 Same as in @"string" in C#
41 """
42 var foo = new Foo ();
43 foo.some_event.connect (callback_a); // connecting the callback functions
44 foo.some_event.connect (callback_b);
45 foo.method ();
46 }