LUA - Mathematics
1 + 2 = 3 ...nothing new for us.
But this is something we can do easier with our calculator. We would not need LUA for this.
However, if we would like to have variables, then we have to write it in opposite.
3 = 1 + 2 or myVar = 1 + 2
Let us remind of: myVar is the name of a storage space. In this storage space we put the result of the addition of 1 + 2. When we call myVar later on, we will get the value 3. (good to know)
Another thing, Robert have not told us until now?
The +
we already know
Operator | Description | Example | Example |
---|---|---|---|
+ | for additing values : | c = a + b | 1 + 3 = 4 |
- | for subtracting values : | c = a - b | 5 - 3 = 2 |
* | for multiplication of values : | c = a * b | 2 * 3 = 6 |
/ | for dividing values : | c = a / b | 8 / 2 = 4 |
^ | for exponentiation of values : | c = a ^ b | 2 ^ 3 = 8 (2 * 2 * 2) |
- | Once more - , this differs to - of subtraction. It is for negation of values. To convert plus to minus and vice versa. | c = - a | if a == 2, then c == -2 |
For sure, this is something everybody knows. This is the beginning of operators for calculation.
If there is something above that is not already known, then I would suggest to take a book for mathematics first.
Yet, one specialty is existing in LUA. A calculation of 2 + "6" will be understood of the programm and 8 will be returned. However, other characters inside the quotes are not allowed (2 + "6s" can not be calculated).
But what is this ? Two "=" in series. How now?
Just a moment. We are going to use our editor (do not belief everything; try to check it by yourself)
To be able to see what the editor will do, we have to learn about the word print.
Briefly, print is a function. Functions will do something (as we have already learned). This function will send information to the screen. Neither more nor less.
Following we feed into the editor:
a = 2 + 1
print (a)

Now we press:
As shown we can press F5 of the arrow (just hidden in the picture) for the same result.
Then a window pop ups somewhere on the screen

We do not know what that means and we want to see the result of what the function print is doing. Moreover, the windows position on the screen is a little bit disturbing.
We are going to change this.
But first we open the window for getting the output/result on the screen.

With this command we open the window which will show us results.
The position of this window is also disturbing and
we change this as well.
These windows can be locked due to there position. That means, we can allocate a fixed place for them. It can be a little bit pedestrian. Pick up the window, move it to the right side of the screen. There are different methods to do so (trial an error).
See my settings below:

The output window (where the results will be shown) is above on the right side of our screen. Below we see the Lua Locals and Lua Globals (we will get to them later on).
The excursion to the settings of the editor has been finished. Now we can use the editor and we promptly see: the editor did his work quit good (better: you did a good job).
The result of our code is shown in the output-window.
(Just a hint: we are going to do more difficult things later on)
However, at the beginning of this chapter I promised to tell you something about the meaning of "==". For this please
have a look to the chapter of Operators of Comparision
Copying of any content of this site (text or graphics) is not allowed, excepted any source code shown in this tutorial. See also: ....Disclaimer
Copyright © Robert Schmitz 2006
Copyright © Robert Schmitz 2006