2.5 Expressions
1; variables tend to be demonstrated in A§2.3; purpose descriptions are demonstrated in A§2.5.9; features calls is described in A§2.5.8; dining table constructors include discussed in A§2.5.7. Vararg expressions, denoted by three dots (‘ . ‘), could only be applied whenever immediately inside a vararg work; they might be explained in A§2.5.9.
Digital workers consist of arithmetic providers (consult A§2.5.1), relational providers (consult A§2.5.2), rational providers (see A§2.5.3), and concatenation driver (discover A§2.5.4). Unary providers make up the unary minus (see A§2.5.1), the unary perhaps not (discover A§2.5.3), additionally the unary length user (read A§2.5.5).
Both work calls and vararg expressions can lead to multiple values. If a manifestation can be used as an announcement (merely feasible for features phone calls (see A§2.4.6)), after that its return checklist was modified to zero elements, thus discarding all came back prices. If a manifestation is used due to the fact finally (or perhaps the sole) element of a list of expressions, next no modification is created (unless the decision is confined in parentheses). In all various other contexts, Lua adjusts the end result list to just one aspect, discarding all principles except initial one.
Any appearance confined in parentheses always results in singular advantages. Hence, (f(x,y,z)) is obviously a single worth, even in the event f comes back several beliefs. (The value of (f(x,y,z)) will be the first benefits returned by f or nil if f will not go back any standards.)
2.5.1 Arithmetic Operators
Lua reinforcement the usual arithmetic operators: your binary + (addition), – (subtraction), * (multiplication), / (division), % (modulo), and ^ (exponentiation); and unary – (negation). When the operands is rates, or strings which can be converted to figures (read A§2.2.1), next all operations possess typical definition. Exponentiation works well with any exponent. Such as, x^(-0.5) computes the inverse of square-root of x . Modulo is understood to be
2.5.2 Relational Workers
Equivalence ( == ) very first compares the kind of the operands. If the types are different, then result is false. Otherwise, the principles on the operands are in comparison. Rates and strings tend to be contrasted inside the usual ways. Items (tables, userdata, threads, and procedures) is contrasted by research: two objects are believed equal only if they are the exact same item. Every time you write a brand new object (a table, userdata, bond, or work), this brand new item differs from any earlier established item.
The conversion process rules of A§2.2.1 don’t apply to equivalence contrasting. Therefore, “0”==0 evaluates to false, and t and t[“0”] denote various records in a table.
The order providers work as follows. If both arguments are rates, chances are they is in comparison as a result. Usually, if both arguments tend to be strings, then their own prices is compared according to research by the present area. If Not, Lua attempts to name the “lt” and/or “le” metamethod (read A§2.8). An assessment a > b is actually translated to b < a and a >= b was converted to b<= a .
2.5.3 Practical Operators
The logical workers in Lua become and, or, and never. Such as the regulation buildings (see A§2.4.4), all sensible providers see both incorrect and nil as incorrect and anything else as true.
The negation agent not necessarily return incorrect or real. The conjunction user and comes back their basic debate if this price try bogus or nil; normally, and return its next argument. The disjunction operator or return its first discussion escort services in Pueblo when this price differs from nil and untrue; usually, or comes back their next debate. Both and and or utilize short-cut evaluation; that will be, the second operand was evaluated as long as necessary. Below are a few advice:
2.5.4 Concatenation
The string concatenation user in Lua try denoted by two dots (‘ .. ‘). If both operands tend to be strings or rates, chances are they include converted to strings in line with the regulations discussed in A§2.2.1. Otherwise, the “concat” metamethod is known as (read A§2.8).