We are now going to replace all the generated code with our own so that we understand what makes an application from the ground up.
hello_vala.vala
file and fill it with this:using GLib; public class Main : Object { public Main () { } static int main (string[] args) { stdout.printf ("Hello, world\n"); return 0; } }
Hello, world
Here we start by looking at the Book
class.
using GLib;
This line says that we are using the GLib
namespace.
public class Main : Object
This is the definition of the Main
class. It is stated here that it is derived from the GLib.Object
class. We don't put the full name GLib.Object
but only Object
because we already stated in the first line that we are using the GLib
namespace.
public Main () { }
The preceding structure is the constructor of the class. Here we have an empty one.
static int main (string[] args) { stdout.printf ("Hello, world\n"); return 0; } }
This is our entry point to the program. If declared as static, the main
function will be considered as the first function that will be run in the application. Without this function, we can't run the application.
And one more thing; there must be one and only one static main
function, otherwise your program will not compile.
Now we should have the generated C code available in the src/
directory. Navigate the filesystem using the Files dock and find hello_vala.c
. Let's open it and see how Vala transforms the Vala code into C code.
We can modify the C code, but your changes will be overwritten whenever you change the Vala code, and the C code will get regenerated.