Skip to content

Commit

Permalink
Deploying to gh-pages from @ 2a7d506 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
colinkiama committed May 3, 2024
1 parent 3e26289 commit 0c6eaf4
Show file tree
Hide file tree
Showing 188 changed files with 26,090 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +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
config: f3c944df982b9a7b31f204f380578135
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file modified .doctrees/environment.pickle
Binary file not shown.
Binary file modified .doctrees/index.doctree
Binary file not shown.
Binary file modified .doctrees/installation-guide.doctree
Binary file not shown.
Binary file added .doctrees/tutorials/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/tutorials/main/index.doctree
Binary file not shown.
1 change: 1 addition & 0 deletions _sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Vala Documentation

About <about>
Installation Guide <installation-guide>
Tutorials <tutorials/index>

Introduction
------------
Expand Down
4 changes: 1 addition & 3 deletions _sources/installation-guide.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Installation Guide

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

.. _Linux Installation Instructions:

Linux
-----

Expand Down Expand Up @@ -71,7 +69,7 @@ You also need to install all the libraries that you want to use individually.
Windows Subsystem for Windows (WSL)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Install a Linux distribution in WSL and then continue with the :ref:`installation instructions for Linux <Linux Installation Instructions>`.
Install a Linux distribution in WSL and then continue with the :ref:`installation instructions for Linux <Linux>`.

Mac OS X
--------
Expand Down
19 changes: 19 additions & 0 deletions _sources/tutorials/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Tutorials
==========

.. toctree::
:hidden:

main/index


Programming Language
--------------------

- `Vala Main Tutorial <main>`_

GUI Programming
---------------

- `GNOME Developer Documenation - Tutorials <https://developer.gnome.org/documentation/tutorials.html>`_
- `elementary OS - Writing Apps <https://docs.elementary.io/develop/writing-apps/the-basic-setup>`_
68 changes: 68 additions & 0 deletions _sources/tutorials/main/01-00-first-program/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
First Program
=============

Your First Program
------------------

Sadly predictable, but still:

.. code-block:: vala
class Demo.HelloWorld : GLib.Object {
public static int main(string[] args) {
stdout.printf("Hello, World\n");
return 0;
}
}
Of course, that is a Vala *Hello World* program. I expect you can recognise some parts of it well enough, but just to be thorough I shall go through it step by step.

.. code-block:: vala
class Demo.HelloWorld : GLib.Object {
This line identifies the beginning of a class definition. Classes in Vala are very similar in concept to other languages. A class is basically a type of object, of which instances can be created, all having the same properties. The implementation of classed types is taken care of by the *gobject* library, but details of this are not important for general usage.

What is important to note is that this class is specifically described as being a subclass of *GLib.Object*. This is because Vala allows other types of class, but in most cases, this is the sort that you want. In fact, some language features of Vala are only allowed if your class is descended from GLib's *Object*.

Other parts of this line show namespacing and fully qualified names, although these will be explained later.

.. code-block:: vala
public static int main(string[] args) {
This is the start of a method definition. A method is a function related to a type of object that can be executed on an object of that type. The static method means that the method can be called without possessing a particular instance of the type. The fact that this method is called ``main`` and has the signature it does means that Vala will recognise it as the entry point for the program.

The *main* method doesn't have to be defined inside a class. However, if it is defined inside a class it must be ``static``. It doesn't matter if it's ``public`` or ``private``. The return type may be either ``int`` or ``void``. With a ``void`` return type the program will implicitly terminate with exit code 0. The string array parameter holding the command line arguments is optional.

.. code-block:: vala
stdout.printf("Hello, World\n");
*stdout* is an object in the *GLib* namespace that Vala ensures you have access to whenever required. This line instructs Vala to execute the method called *printf* of the *stdout* object, with the hello string as an argument. In Vala, this is always the syntax you use to call a method on an object, or to access an object's data. ``\n`` is the escape sequence for a new line.

.. code-block:: vala
return 0;
``return`` is to return a value to the caller and terminate the execution of the *main* method which also terminates the execution of the program. The returned value of the *main* method is then taken as the exit code of the program.

The last lines simply end the definitions of the method and class.

Compile and Run
---------------

Assuming you have Vala installed, then all it takes to compile and execute this program is:

.. code-block:: console
$ valac hello.vala
$ ./hello
*valac* is the Vala compiler, which will compile your Vala code into a binary. The resulting binary will have the same name as the source file and can then be directly executed on the machine. You can probably guess the output.

If you get some warnings from a C language compiler, please jump to :doc:`/tutorials/main/07-00-tools/07-01-valac` for the reason and solution.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Source Files and Compilation
============================

Vala code is written in files with *.vala* extensions. Vala does not enforce as much structure as a language like Java - there are no concepts of packages or class files in the same way. Instead structure is defined by text inside each file, describing the logical location of the code with constructs such as namespaces. When you want to compile Vala code, you give the compiler a list of the files required, and Vala will work out how they fit together.

The upshot of all this is that you can put as many classes or functions into a file as you want, even combining parts of different namespaces in together. This is not necessarily a good idea. There are certain conventions you probably want to follow. A good example of how to structure a project in Vala is the Vala project itself.

All source files for the same package are supplied as command line parameters to the Vala compiler ``valac``, along with compiler flags. This works similarly to how Java source code is compiled. For example:

.. code-block:: console
$ valac compiler.vala --pkg libvala
will produce a binary with the name *compiler* that links with the package ``libvala``. In fact, this is how the *valac* compiler is produced!

If you want the binary to have a different name or if you have passed multiple source files to the compiler you can specify the binary name explicitly with the ``-o`` switch:

.. code-block:: console
$ valac source1.vala source2.vala -o myprogram
$ ./myprogram
If you give *valac* the ``-C`` switch, it won't compile your program into a binary file. Instead it will output the intermediate C code for each of your Vala source files into a corresponding C source file, in this case *source1.c* and *source2.c*. If you look at the content of these files you can see that programming a class in Vala is equivalent to the same task in C, but a whole lot more succinct. You will also notice that this class is registered dynamically in the running system. This is a good example of the power of the GNOME platform, but as I've said before, you do not need to know much about this to use Vala.

If you want to have a C header file for your project you can use the ``-H`` switch:

.. code-block:: console
$ valac hello.vala -C -H hello.h
12 changes: 12 additions & 0 deletions _sources/tutorials/main/02-00-basics/02-02-syntax-overview.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Syntax Overview
===============

Vala's syntax is an amalgam heavily based on C#'s. As a result, most of this will be familiar to programmers who know any C-like language, and in light of this I have kept things brief.

Scope is defined using braces. An object or reference is only valid between ``{`` and ``}``. These are also the delimiters used to define classes, methods, code blocks etc, so they automatically have their own scope. Vala is not strict about where variables are declared.

An identifier is defined by its type and a name, e.g. ``int c`` meaning an integer called *c*. In the case of value types this also creates an object of the given type. For reference types these just define a new reference that doesn't initially point to anything.

Identifier names may be any combination of letters ([a-z], [A-Z]), underscores and digits. However, to define or refer to an identifier with a name that either starts with a digit or is a keyword, you must prefix it with the '@' character. This character is not considered a part of the name. For example, you can name a method *foreach* by writing ``@foreach``, even though this is a reserved Vala keyword. You can omit the '@' character when it can be unambiguously interpreted as an identifier name, such as in "foo.foreach()".

Reference types are instantiated using the ``new`` operator and the name of a construction method, which is usually just the name of the type, e.g. ``Object o = new Object()`` creates a new Object and makes *o* a reference to it.
18 changes: 18 additions & 0 deletions _sources/tutorials/main/02-00-basics/02-03-comments.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Comments
========

Vala allows comments in code in different ways.

.. code-block:: vala
// Comment continues until end of line
/* Comment lasts between delimiters */
/**
* Documentation comment
*/
These are handled in the same way as in most other languages and so need little explanation. Documentation comments are actually not special to Vala, but a documentation generation tool like :doc:`Valadoc </developer-guides/valadoc>` will recognise them.

Loading

0 comments on commit 0c6eaf4

Please sign in to comment.