Basic syntax and keywords
Here we describe basic concepts that will help you understand the scripts that will be shown in the next section.
Variables
Variables are the way Lua (and other computer languages) allow referring to locations in memory. For instance, you can create a variable called PI
that stores the number 3.14159
.
Now that your computer has the number 3.14159
stored in its memory and it knows you decided to call it PI
, you can use it in a very convenient way. For example:
As we will show later, variables do not need to be number, but also text and some other more sofisticated types.
Comments
Comments are lines of your script that are ignored by your computer. That means that you can write whatever you want, without worrying about syntax and other programming issues. For that reason, they become a very convenient to add any sort of information that will help you and others understand what you did.
You can also multiline comments as follows
Keywords
It is mentioned in the Lua documentation that:
Lua is a free-form language. It ignores spaces (including new lines) and comments between lexical elements (tokens), except as delimiters between names and keywords.
Names (also called identifiers) in Lua can be any string of letters, digits, and underscores, not beginning with a digit and not being a reserved word. Identifiers are used to name variables, table fields, and labels.
However, not every name is allowed. There are some variables that Lua has reserved for its own syntax, thus you are not allowed to use them. These are
In addition to those, there are a few keywords that Emp has reserved for itself:
We have seen auto_solve
before. In addition to that one, print_results
allows controlling if Emp will print the results to the stdout
or not. The others are absolutely useless to you, so just avoid them.
Last updated