Vala

From Mario Fan Games Galaxy Wiki
Vala
Kermit.gif
Basics
Intermediate
none
Advanced
none
Add to this template
 Stub.png This article or section is in need of expansion.

Please add further information.


Vala is a programming language with a syntax similar to C#.

Hello World example

This is very similar to a C# Hello World program. In Vala the main function doesn't need to be in a class, but in this example it is.

Code

using GLib;

public class Hello : GLib.Object {
    public static int main (string[] args) {
        stdout.printf ("Hello world!\n");
        
        return 0;
    }
}

Explanation

using GLib;

We want to use things from namespace GLib. This row is optional -- the compiler includes it anyway.

public class Hello : GLib.Object {

Now we create a new class that is derived from GLib.Object. Every class should derive from it.

    public static int main (string[] args) {

The main entry point of every Vala program is called 'main'. If it is in a class, it must be static.

        stdout.printf ("Hello world!\n");

Self-explanatory. '\n' means a new line.

        return 0;

0 means that nothing has failed.

    }
}

Closing the braces.

Compilation

($ means the command prompt.)

Compile it with

$ valac -o hello helloworld.vala

to produce an executable file named 'hello'.

Or just

$ valac helloworld.vala

to produce an executable file named by the file name.

Now run it:

$ ./hello
Hello world!

See also