Lua data types

Содержание

Слайд 2

Слайд 3

WHAT IS “LUA”? Lua (/ˈluːə/ loo-ə, from Portuguese: lua [ˈlu.(w)ɐ] meaning

WHAT IS “LUA”?

Lua (/ˈluːə/ loo-ə, from Portuguese: lua [ˈlu.(w)ɐ] meaning moon)

is a lightweight multi-paradigm programming language designed primarily for embedded systems and clients. Lua is cross-platform since it is written in ANSI C, and has a relatively simple C API.
Слайд 4

Слайд 5

Слайд 6

Strings enclosed in double quotes are interpreted C-like escape sequences, starting

Strings enclosed in double quotes are interpreted C-like escape sequences, starting

with the "\" character (backslash):
\ B (blank)
\ N (newline)
\ R (carriage return);
\ T (horizontal tab)
\\ (Backslash);
\ '' (Double quote);
\ '(Single quote).
Слайд 7

Note The symbol in the line may also be represented by

Note
The symbol in the line may also be represented by their

code using the escape-sequence:
\ Ddd,
where ddd - a sequence of no more than three digits.
Слайд 8

Also quotes to define string double square brackets can also be used:

Also quotes to define string double square brackets can also be used:

Слайд 9

Defining line by using double square brackets allows you to ignore

Defining line by using double square brackets allows you to ignore all

the escape-sequence, ie, the string is created entirely as described..:
Слайд 10

Note When determining the line by using double square brackets accounted

Note
When determining the line by using double square brackets accounted for

tabs, and transport.
Double brackets can be nested. In order to prevent any confusion, the symbol "equal" (=) is inserted between the brackets:
Слайд 11

Function. Functions in Lua can be stored in variables, passed as

Function. Functions in Lua can be stored in variables, passed as arguments to

other functions, and returned as the function result.
Table. The table is a set of pairs of the "key" - "value", which are called fields or table elements. As the keys and values ​​of table fields may be of any type, except nil. The tables do not have fixed size: at any time, they can add an arbitrary number of elements.
Userdata (user data). It is a special type of data. Values ​​of this type can not be created or modified directly in Lua-script.
Userdata used to represent new types created in the calling program or script libraries written in C. For example, the Lua extension library for « CronosPRO » use this type to represent objects such as:
Data banks (Bank class);
database (Base Class);
recording (Record class) and so on. n.
Thread. It represents a stream of execution. These flows are in no way associated with the operating system and supported solely by means of Lua.
Слайд 12

Lua does not provide explicitly specify the type of the variable.

Lua does not provide explicitly specify the type of the variable. The

variable type is set at the time of assignment of variable values. Any variable value may be assigned to any type (whether, what type of value it contained before).
Слайд 13

note Variables table, function, thread and userdata do not contain the

note
Variables table, function, thread and userdata do not contain the actual

data, and store links to related sites. When you assign, transfer to the function as an argument and return of function as a result of copying objects does not occur, are copied by reference to them.
Слайд 14

The remaining data are immediate values.

The remaining data are immediate values.

Слайд 15

AS IN LUA GET THE TYPE OF A VARIABLE? Type of

AS IN LUA GET THE TYPE OF A VARIABLE?

Type of value

stored in a variable, you can find out by using the standard function type. This function returns a string containing the name of the type ( «nil», «number», «string», «boolean», «table», «function», «thread», «userdata»).
Слайд 16

AS IN LUA CONVERT THE VARIABLE TYPE? Lua if necessary automatically

AS IN LUA CONVERT THE VARIABLE TYPE?

Lua if necessary automatically converts the

number of the line and vice versa. For example, if the string value is an operand in an arithmetic operation, it is converted to a number. Similarly, the numerical value, to meet at the place where the string will be converted to a string.
Слайд 17

The value of any type can be explicitly converted to a

The value of any type can be explicitly converted to a

string using the standard tostring function.
Слайд 18

From the above example it is clear that the contents of

From the above example it is clear that the contents of the

table function tostring not converted. Perform this conversion, you can use render function.
Слайд 19

To explicitly convert a value to the number you can use

To explicitly convert a value to the number you can use

the standard function tonumber. If the value is a string that can be converted into a number (or already is a number), the function returns the result of conversion, otherwise it returns nil.