Val (hal) a

avatar
(Edited)

Programming

When you do not C that well, yet want to code in it.

Trans-compiling

Now that seems like very 'now' and 'these-days', so it must be very modern. Vala is, as that is what I am referring to. And I want to stay far away from any discussion about Vala being a programming language or not. Because I am able to write software in it, compile and run that, it is as close to programming language as it gets. Started this day with coffee, my development laptop and a basic understanding of Vala. And if you want to join in I expect that you know how to set up the right development environment in Linux. This is not so much a tutorial, as it is more like an experience series. In the source-code that I share with you, you can also see some questions. And if you can be of help, I will appreciate that with some GNK and MCD Tokens.

Transform-compilation is where one programming language first gets translated into another one. After which it gets compiled into an executable file from there. For Vala this means that it first gets translated into C and after that it gets compiled into an executable file. Just try to Transform a Vala sourcecode to its C result and have a peek into that file. Maybe then you understand why I do dislike the C language so very much, but still appreciate its potential. Not being a programmer, yet more like a technical innovation Geek, I like the KISS principle: Keep It Simply Stupid. And when I discovered Vala I felt like this might be a great thing to use. As I want to focus more on Blockchain automation development, this thing might be my programming Val (hal) a.

Compiling is easy using valac from the terminal, just bashing away. The size of the executable is amazingly small, less than 20 KiloBytes! Only thing that still puzzles me is that I can only seem to be able to run the executable from a terminal. Do you know how that can be fixed, let me know and I will send you some GNK and MCD. (Made a krul.sh file, that runs it, but I want to run it, by double clicking it on a Desktop, for instance.) This is all done using Linux, GTK should be cross-platform, as is Vala, but I will only focus on using Vala on Linux.

Have fun with it!

LINKS

Vala

Usage

Editor


Trans-Compiling using Vala

Make sure you are in the right source-code folder.

valac krul.vala --pkg gtk+-3.0


If you only want the C code.

valac krul.vala --pkg gtk+-3.0 -C

Run it with a krul.sh file

Make it executable.

\FILE: krul.sh

/home/yourhomefolder/yourvalaprojects/curlit/krul

/FILE: krul.sh

The Vala source-code

\FILE: krul.vala

/**
 *
 * First step into the Twilight zone of Val(hal)a
 * By Oaldamster: https://steemit.com/@oaldamster
 *
 * Version 202002131050-0.0.0.1-beta
 *
**/

//  How to implement Curl, coming up next...
//using Curl
//  Why is using Gtk not needed in this case...!?
//using Gtk

public class CurlyWindow : Gtk.Window {
    /**
     *
     *  This class thing, trying to wrap my head around it. :/
     *
     **/
    // Set some constant INTeger variables for the Window defaultsize.
    private const int DEFAULT_WIDTH = 800;
    private const int DEFAULT_HEIGHT = 600;
    // A constant, only known to its class
    private const string KRUL_WINDOW_TITLE = "Krul to Curl";
    // Mind boggling; Calls CurlyWindow Class main or construct?
    public CurlyWindow () {}

    construct {
        /**
         *
         * If I remember correctly...
         * Construct is only called once.
         * When a Class is being created with 'new'
         *
         * Using 'this' to make it more understandable.
         * (For me, that is.)
         *
         **/

        // Set a default title
        this.title = CurlyWindow.KRUL_WINDOW_TITLE;
        // Make it a toplevel window type
        this.type = CurlyWindow.TOPLEVEL;
        // Default size of the window
        this.set_default_size (DEFAULT_WIDTH, DEFAULT_HEIGHT);
        // Make it all visible
        this.show_all ();
        // Handles the events
        do_events ();
    }

    private void do_events () {
        // Quit the show
        destroy.connect (Gtk.main_quit);
    }

    public static int main (string[] args) {
        // Initialize Gtk
        Gtk.init (ref args);

        // Create a new Window object
        var curlyWindowHandle = new CurlyWindow ();
        // If it worked, it should change the title.
        curlyWindowHandle.title = "Did it work?";

        // Go go go Gtk Main.
        Gtk.main ();
        // Return zero if okay, a negative value means trouble.
        return 0;
    }
}

/FILE: krul.vala



Okay, I know, it is just a window...
2020-02-13-130203_1366x768_scrot.png
Screenshot cc-by-sa @oaldamster



0
0
0.000
0 comments