Vala Helloworld!

Vala HelloWorld!

Here i want to show a simple HelloWorld-based app written in Vala!
 

Hi Everyone! I’m starting my studies in Vala programming language,and i want to tell how i’m going 🙂 So i start posting a simple helloworld,that can be extended to a great Vala example 🙂

First of all,in Debian-based GNU/Linux distribution,install Vala!

$ sudo apt-get install valac vala-utils vala-doc valac-dbg

Now we start making a main.vala file!

class MyFirst.HelloWorld : GLib.Object {

    public static int main(string[] args) {

        stdout.printf("Hello, World\n");

        return 0;
    }
}

Save it,compile and run!

$ valac main.vala
$ ./main.vala
  Hello, World

Why we don’t make it a bit more interesting? So:

class MyFirst : GLib.Object {
  public string ask_your_name() {
    stdout.printf("Please,enter a text,it'll be repeated: ");
    string input = stdin.read_line();
    return input;
  }
  public void print_this(string text) {
    stdout.printf(text);
  }
  public static int main(string[] args) {
    MyFirst m_1 = new MyFirst();
    string text = m_1.ask_your_name();
    stdout.printf("\nSee your text repeated now:");
    m_1.print_this(text + "\n");
    return 0;
  }

It really toke a bit more of lines 🙂 Compile it and check!

Thanks! Wait for more tutorials 🙂

See ya!

Advertisements

About barklome

This is angelox's (or barklome) personal blog. Talking about Embedded Linux things,Free Software Things,and tutorials about how-to-use free software.
This entry was posted in Vala. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s