Documentation

Better explanation about the guaranties of multiple assignment in
the manual.
This commit is contained in:
Roberto Ierusalimschy 2021-10-11 13:49:13 -03:00
parent deac067ed3
commit 87a9573b2e
4 changed files with 13 additions and 5 deletions

View File

@ -64,7 +64,7 @@ static int getbaseline (const Proto *f, int pc, int *basepc) {
} }
else { else {
int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */ int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */
/* estimate must be a lower bond of the correct base */ /* estimate must be a lower bound of the correct base */
lua_assert(i < 0 || lua_assert(i < 0 ||
(i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc)); (i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc));
while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc) while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc)

View File

@ -1217,7 +1217,7 @@ static const char *get2digits (const char *s) {
/* /*
** Chech whether a conversion specification is valid. When called, ** Check whether a conversion specification is valid. When called,
** first character in 'form' must be '%' and last character must ** first character in 'form' must be '%' and last character must
** be a valid conversion specifier. 'flags' are the accepted flags; ** be a valid conversion specifier. 'flags' are the accepted flags;
** 'precision' signals whether to accept a precision. ** 'precision' signals whether to accept a precision.

2
lvm.c
View File

@ -1109,7 +1109,7 @@ void luaV_finishOp (lua_State *L) {
#define ProtectNT(exp) (savepc(L), (exp), updatetrap(ci)) #define ProtectNT(exp) (savepc(L), (exp), updatetrap(ci))
/* /*
** Protect code that can only raise errors. (That is, it cannnot change ** Protect code that can only raise errors. (That is, it cannot change
** the stack or hooks.) ** the stack or hooks.)
*/ */
#define halfProtect(exp) (savestate(L,ci), (exp)) #define halfProtect(exp) (savestate(L,ci), (exp))

View File

@ -1346,8 +1346,10 @@ then all values returned by that call enter the list of values,
before the adjustment before the adjustment
(except when the call is enclosed in parentheses; see @See{expressions}). (except when the call is enclosed in parentheses; see @See{expressions}).
The assignment statement first evaluates all its expressions If a variable is both assigned and read
and only then the assignments are performed. inside a multiple assignment,
Lua ensures all reads get the value of the variable
before the assignment.
Thus the code Thus the code
@verbatim{ @verbatim{
i = 3 i = 3
@ -1367,6 +1369,12 @@ x, y, z = y, z, x
} }
cyclically permutes the values of @id{x}, @id{y}, and @id{z}. cyclically permutes the values of @id{x}, @id{y}, and @id{z}.
Note that this guarantee covers only accesses
syntactically inside the assignment statement.
If a function or a metamethod called during the assignment
changes the value of a variable,
Lua gives no guarantees about the order of that access.
An assignment to a global name @T{x = val} An assignment to a global name @T{x = val}
is equivalent to the assignment is equivalent to the assignment
@T{_ENV.x = val} @see{globalenv}. @T{_ENV.x = val} @see{globalenv}.