Wiki page hello-world.md changed with summary [Proofreading by Nate Pass 1] by Nate Drake

This commit is contained in:
Nate Drake 2017-10-27 03:58:04 -07:00 committed by apache
parent fa9dbc01b9
commit 2d7e89571f
1 changed files with 24 additions and 24 deletions

View File

@ -4,13 +4,13 @@
# Tutorial 1: Hello World #
This tutorial will guide you through the necessary steps to build your first "Hello World" example using the _Enlightenment Foundation Libraries_ (EFL). Make sure you have read the [Setting up the development environment](devenv-setup.md) guide.
This tutorial will guide you through the necessary steps to build your first "Hello World" example using the _Enlightenment Foundation Libraries_ (EFL). Before continuing make sure you have read the [Setting up the development environment](devenv-setup.md) guide.
Don't be afraid, there is very little code in this first tutorial. The main goal is to be able to build and execute an application using EFL. We will be assuming that you know how to program in C, though. Should we start?
There is very little code in this first tutorial so don't worry if you have little coding experience. The main goal is to build and execute an application using EFL. You will need a basic knowledge of C to get started however.
## The Program ##
Copy the following program into a text file named ``hello-world.c``. Don't worry if you don't understand all of it right away, we are going to explain every bit afterwards in the Walkthrough section.
Using your favorite text editor, copy the below code into a new file and save as ``hello-world.c``. Don't worry if you don't understand all of it right away, you'll see how each part of the code works in the Walkthrough section below.
```c
#include <Eina.h>
@ -28,43 +28,43 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
EFL_MAIN()
```
Now build the application as described in the [Setting up the development environment](devenv-setup.md#Building) guide. As a quick reminder, this is the required command if you are using the ``gcc`` compiler:
Next, build this application as outlined in our guide in [Setting up the development environment](devenv-setup.md#Building). If you are using the ``gcc`` compiler, run:
```bash
gcc -o hello-world hello-world.c `pkg-config --cflags --libs eina efl elementary` -DEFL_EO_API_SUPPORT=1 -DEFL_BETA_API_SUPPORT=1
```
If you got no warnings in the process, your program should be ready. Go ahead and test it! Just type:
If the systems displays no errors, your program should be ready. Test it by typing:
```bash
./hello-world
```
And you should see the words ``Hello World!`` printed on the screen.
The words ``Hello World!`` will now appear on the screen.
## Walkthrough ##
### Includes ###
Let's begin with the ``include``s section:
Let's start by focusing on the ``include``s section:
```c
#include <Eina.h>
#include <Efl.h>
#include <Elementary.h>
```
The EFL is split in several libraries, and you only need to include the ones you actually want to use. In this tutorial we are calling methods from the ``Eina`` and ``Efl`` libraries, therefore we need to include the ``"Eina.h"`` and ``"Efl.h"`` headers.
The EFL is split into several libraries. You only need to include the ones you actually want to use. In this tutorial we are calling methods from the ``Eina`` and ``Efl`` libraries, therefore we need to include the ``"Eina.h"`` and ``"Efl.h"`` headers.
> **NOTE:**
> As of now, the ``"Elementary.h"`` header is special. It will be removed soon.
If you are unsure about which libraries your program is actually using, look at the prefix of the EFL methods and macros you use. In this case, we use ``eina_``, ``EINA_``, ``efl_`` and ``EFL_``.
If you're not sure which libraries your program is actually using, just look at the prefix of the EFL methods and macros. In this case, we're using ``eina_``, ``EINA_``, ``efl_`` and ``EFL_``.
Take a look at the [List of EFL libraries](list-of-efl-libraries.md) article if you are curious about the purpose of each one (This will be covered in a later tutorial, though).
We will cover this in more depth in a later tutorial but feel free to take a look at the [List of EFL libraries](list-of-efl-libraries.md) article to discover the purpose of each one if you wish.
### Main function ###
Instead of the ``main()`` function marking the standard C entry point, we use ``efl_main()``:
Instead of the ``main()`` function marking the standard C entry point, we're using ``efl_main()``:
```c
void
@ -73,11 +73,11 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
}
```
EFL will take care of all initialization tasks and call your ``efl_main()`` method when everything is ready to go.
EFL takes care of all initialization tasks and calls your ``efl_main()`` method when everything is ready.
We will pay attention to the parameters of ``efl_main()`` in the following tutorial. In this one, we are not using them, and hence the ``EINA_UNUSED`` macro: it is optional, but it gets rid of warnings regarding unused parameters on some compilers, so it is worth having.
We will focus on the ``efl_main()`` parameters in the following tutorial. In this one, we're not using them hence the ``EINA_UNUSED`` macro. This is optional, but it gets rid of warnings regarding unused parameters, so it's worth having.
The next line is a regular C ``printf()`` which will output our favourite string to the console, not much to comment there.
The next line is a regular C ``printf()`` which will output the 'Hello World' string to the console:
```c
printf("Hello World!\n");
@ -85,33 +85,33 @@ printf("Hello World!\n");
### Exiting ###
**Programs made with EFL must always finish by calling** ``efl_exit()``. This is an important difference with the regular C ``main()``, where it is enough to let control reach the end of the method to finish the program.
**Any programs you create with EFL must always terminate by calling** ``efl_exit()``. This is an important difference with the regular C ``main()``, where a program exits when it reaches the end of a method.
```c
efl_exit(0);
```
The single parameter of ``efl_exit()`` is the value that your program will return to the operating system.
The parameter ``efl_exit()`` is the value your program returns to the operating system.
### Automatic EFL setup and shutdown ###
Finally, the last piece of "boilerplate" code. It has to be included at the end of every EFL program.
This final piece of "boilerplate" code must be included at the end of every EFL program:
```c
EFL_MAIN()
```
As you might have guessed, it defines the real ``main()`` method that every C program requires, which deals with initialization and deinitilization tasks and eventually calls the ``efl_main()`` that you defined above.
It defines the real ``main()`` method required by C Programs, which deals with initialization and deinitilization tasks. It also eventually calls the ``efl_main()`` method that you defined above.
It is not mandatory, but it simplifies setup and shutdown processes considerably, so we are going to use it throughout all the tutorials.
This is not mandatory, but it simplifies the setup and shutdown processes considerably, so we are going to use it in this series of tutorials.
## Conclusion ##
We hope that, as promised, this has not been too painful. Let's recap what we have learnt today.
Hopefully you will not have found this tutorial too difficult. So far you have learned:
* That you have to include the header files for the EFL libraries you intend to use. Typically, ``Eina.h`` and ``Efl.h``.
* That your main method should be ``efl_main()``.
* That your EFL programs should **always** call ``efl_exit()`` at some point.
* That your EFL programs should include the ``EFL_MAIN()`` macro at the end, so EFL can insert its setup and shutdown code.
* Header files must be included for any EFL libraries you intend to use. Typically, these are ``Eina.h`` and ``Efl.h``.
* Your main method should be ``efl_main()``.
* Your EFL programs should **always** call ``efl_exit()`` at some stage.
* Your EFL programs should include the ``EFL_MAIN()`` macro at the end, so EFL can insert its own start and shutdown code.
The next tutorial keeps introducing more basic concepts, and shows how to retrieve the command line parameters passed to your program. See you there!