Skip to content

Commit

Permalink
Deploying to gh-pages from @ 3d0e291 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
colinkiama committed Apr 1, 2024
1 parent 5bb2970 commit 8e101cb
Show file tree
Hide file tree
Showing 100 changed files with 13,196 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: c2ab5f9afc6cc953b57fec8ffe14a7ca
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file added .doctrees/environment.pickle
Binary file not shown.
Binary file added .doctrees/index.doctree
Binary file not shown.
Binary file added .doctrees/tutorial/01-00-introduction.doctree
Binary file not shown.
Binary file added .doctrees/tutorial/02-00-getting-started.doctree
Binary file not shown.
Binary file added .doctrees/tutorial/02-01-installation.doctree
Binary file not shown.
Binary file added .doctrees/tutorial/02-02-hello-world.doctree
Binary file not shown.
Binary file added .doctrees/tutorial/02-03-basic-debugging.doctree
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/tutorial/03-01-variables.doctree
Binary file not shown.
Binary file added .doctrees/tutorial/03-02-numbers.doctree
Binary file not shown.
Binary file added .doctrees/tutorial/03-03-bools-and-ifs.doctree
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/tutorial/03-05-loops.doctree
Binary file not shown.
Binary file added .doctrees/tutorial/04-00-parrot-program.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/tutorial/05-00-methods.doctree
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/tutorial/05-02-main-method.doctree
Binary file not shown.
Binary file added .doctrees/tutorial/index.doctree
Binary file not shown.
Empty file added .nojekyll
Empty file.
10 changes: 10 additions & 0 deletions _sources/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Vala Documentation
==================

This is the Vala Documentation website

.. toctree::
:hidden:

Tutorial <tutorial/index>

28 changes: 28 additions & 0 deletions _sources/tutorial/01-00-introduction.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Introduction
============

Vala is an object-oriented programming language with a self-hosting compiler that generates C code and uses the GObject type system.

Vala is designed to allow access to existing C libraries, especially GObject-based libraries, without the need for runtime bindings.

All that is needed to use a library with Vala is an API file, containing the class and method declarations in Vala syntax.

Vala currently comes with bindings for GLib and GTK+ and many others from the GNOME Platform.

Vala can also be used to create C libraries too.

The syntax of Vala is inspired by C# and Java, so if you have used either of those, you'll seamlessly adapt to writing Vala code.

Why Vala?
---------

- Comfortably write your code in an object-oriented way with high level abstractions, while having access to deep integrations with GNOME technolgies such as: GObject, GTK and more!
- Vala compiles code down to blazingly fast, fully native binaries. You're also able to reuse existing C Code in your Vala programs as well as generate C Code from Vala.
- Vala is free and open-source software. It has a great community that contributes to the compiler and develops lots of tooling.

Who is this tutorial for?
-------------------------

This tutorial is for anybody intrested in learning Vala. This tutorial is written
with the assumption that the reader is a beginner at programming so we do make an
effort to explain programming concepts and practices throught the tutorial.
15 changes: 15 additions & 0 deletions _sources/tutorial/02-00-getting-started.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Getting Started
===============

In this chapter, we will:

- Explain how to Install Vala
- Guide you through writing your first Vala Program
- Teach techniques that will help you fix errors in Vala programs

.. toctree::
:hidden:

Installation <02-01-installation>
Hello World <02-02-hello-world>
Basic Debugging <02-03-basic-debugging>
115 changes: 115 additions & 0 deletions _sources/tutorial/02-01-installation.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
Installation
============

Vala is available on multiple operating systems. Follow the isntallation instructions below for your operating system.

.. _linux:

Linux
-----

Vala is available on a large variety of Linux distributions.
Mostly you want to install other development files for libraries, that you want to use with vala.

Fedora
~~~~~~

Development files usually come in ``*-devel`` packages, for example ``libgee-devel``.

.. code-block:: console
$ sudo dnf install vala
Debian
~~~~~~

You need to install ``*-dev`` packages, to get development files on Debian.

.. code-block:: console
$ sudo apt install valac
Arch Linux
~~~~~~~~~~

.. code-block:: console
$ sudo pacman -S vala
\*BSD
-----

First you install the port:

.. code-block:: console
$ cd /usr/ports/lang/vala/ && make install clean
And then you can add the package:

.. code-block:: console
$ pkg install vala
Windows
-------

MSYS2
~~~~~

MSYS2 provides a Linux-like environment for Windows. First install `MSYS2 <https://www.msys2.org>`__,
then vala:

.. code-block:: console
$ pacman -S mingw-w64-x86_64-gcc
$ pacman -S mingw-w64-x86_64-pkg-config
$ pacman -S mingw-w64-x86_64-vala
You also need to install all libraries you want to use individually.

Windows Subsystem for Windows (WSL)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Install a Linux distribution in WSL and then go on with the :ref:`installation instructions for Linux <linux>`.

Mac OS X
--------

To install Vala on you can use `brew <https://brew.sh>`__, a package manager for OS X:

.. code-block:: console
$ brew install vala
Verifying the Installation
--------------------------

If you installed everyting correctly, if enter this line in your terminal:

.. code-block:: console
$ valac --version
A line like this should be printed in the terminal:

.. code-block:: output
Vala x.xx.x
If you don't see any version number and instead see something like along the lines of ``The command 'valac' is not recognised`` or any other error, this means that Vala has not been installed correctly.

Please ensure that you've followed the installation instructions above and try again.

.. warning::

The minimum required Vala version for this tutorial is 0.56.0. You must have this version (or a higher version number) of Vala installed after following the instructions below

If not, we can't guarantee that anything we've explained in this tutorial will work on your system.

If you are struggling to either:

- Install Vala
- Meet the minimum required Vala version requirement

`Try asking the community for help <https://vala.dev/#community>`_.
150 changes: 150 additions & 0 deletions _sources/tutorial/02-02-hello-world.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
Hello World
===========

In this section, we'll:

- Explain the steps for you to create directories on your system, where you'll store the Vala programs you will be creating in this tutorial
- Help you create our first Vala program
- Teach you the essential parts that make up a Vala program
- Breifly explain how Vala relates to the C Programming Language


Setting up your directories
---------------------------

Firstly, you'll create a directory where you'll store all of your Vala projects for this tutorial.
We suggest making one in your home directory.

Open a terminal and enter the commands below to create a ``ValaProjects`` directory in your home directory and ``HelloWorld`` directory inside of the ``ValaProjects`` directory.

On Unix-based systems (Linux, macOS, \*BSD, etc.) and Powershell in Windows, enter these commands:

.. code-block:: console
$ mkdir ~/ValaProjects
$ cd ~/ValaProjects
$ mkdir HelloWorld
$ cd HelloWorld
If you are using CMD in Windows, enter these commands:

.. code-block:: doscon
> mkdir "%USERPROFILE%\ValaProjects"
> cd /d "%USERPROFILE%\ValaProjects"
> mkdir HelloWorld
> cd HelloWorld
Creating your first Vala program
--------------------------------

Next, create make a new Vala source file inside the ``HelloWorld`` directory called ``main.vala``. This is where you'll write the code for you first Vala program.

Now in ``main.vala``, add the following code below:

.. code-block:: vala
:caption: main.vala - A program that prints "Hello, world!"
public static void main () {
print ("Hello, world!\n");
}
.. note::

In this tutorial, Vala code will be indented with 4 spaces since all Vala code written in this tutorial will follow the `elementary coding style <https://docs.elementary.io/develop/writing-apps/code-style>`_ (unless specified otherwise).

After you've added the code above to the ``main.vala`` source file, save the file then, return to your terminal you opened earlier.

On Unix-based systems (Linux, macOS, \*BSD, etc), enter the following commands to build and run the file:

.. code-block:: console
$ valac main.vala
$ ./main
If you're using Windows, you need to replace ``.\main.exe`` instead of ``.\main`` when entering the commands:

.. code-block:: doscon
> valac main.vala
> ./main.exe
You should see the following line added to your terminal: "Hello, world!".

You've successfully created your first Vala program. Congratulations!

What just happened?
-------------------

Let's break down the anatomy of the program you've just created so that you can understand what just happened.

.. code-block:: vala
:emphasize-lines: 1, 3
public static void main () {
print ("Hello, world!\n");
}
The highlighted lines above define a **method** in Vala; A method is a block of code that contain code for the program to execute when called.

The ``main`` **method** in Vala is special becasue it's the first **method** that runs in a Vala program. The program automatically calls the ``main`` **method** first.

We'll explain ``public``, ``static`` and ``void`` in later chapters.

The curly brackets (``{}``) define the start and end of the **method** body. Our program runs the code written in each line between the curly brackets for the ``main`` **method**.

The ``main`` **method** contains the following code:

.. code-block:: vala
:emphasize-lines: 2
public static void main () {
print ("Hello, world!\n");
}
The highlighted line above line prints the "Hello, world!" text on the screen.

``print`` is also a method. Unlike the ``main`` method, you are calling the ``print`` method yourself.

"Hello, world!\\n" is a **string**; A **string** is a sequence of characters such as letters, numbers, symbols and spaces. We'll go into more details about strings in the next chapter.

You passed in the "Hello, world\\n" **string** into the ``print`` method as an argument to specify the **string** we want to be displayed in the terminal; An argument is a piece of information that may be used in an program. We'll go into more detail about arguments in methods in later chapters.

However, "\\n" wasn't actually displayed when we ran the program. This is because "\\n" is a special type of character called an "escape sequence". "\\n" adds a new line to the terminal.

If you build and run the program without "\\n", What ever is added next in the terminal will start on the same line as "Hello, world!". We'll find out more about escape sequences in later chapters.

The Vala Compiler
-----------------

.. code-block:: console
$ valac main.vala
The line above is tells the Vala compiler to build the program with the code we've written in ``main.vala``.

This step is completely separate from running your code with ``./main`` or ``./main.exe``.

Once your program has been built successfully, we can run it any time without having to compile again.

The compiler program ``valac`` is fine for small projects however, once you start working on bigger, more complex projects, we'll introduce a build system that you'll work with instead of using ``valac`` directly.

The relationship between Vala and C
-----------------------------------

When you enter the command: ``valac main.vala``, ``valac`` performs the following steps:

1. Generate C Code from the Vala code we've written
2. Call the C Code compiler on installed on our system to build an binary executable from the generate C Code.

Normally, when compiling your code with ``valac``, you don't notice step 1 however, you can actually see the generated C code by adding the ``-C`` flag to ``valac`` commands.

If you run:

.. code-block:: console
$ valac -C main.vala
Instead of an new exectuable file being created, a file called ``main.c`` will be created instead. This is the generated C code from step 1.

Details on working with C Code are out of the scope of this tutorial however, this is key to understanding how some of the language's features are possible later chapters.
Loading

0 comments on commit 8e101cb

Please sign in to comment.