summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-05-28 15:46:49 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-05-28 15:46:49 -0300
commitb293ae0577bebaca7169cb4f041b800641d5e2c4 (patch)
treebda609d72277433bda3537ac50ed8fecf9a73898
parentd9f40e3f6fb61650240c47d548bee69b24b07859 (diff)
downloadlua-b293ae0577bebaca7169cb4f041b800641d5e2c4.tar.gz
lua-b293ae0577bebaca7169cb4f041b800641d5e2c4.tar.bz2
lua-b293ae0577bebaca7169cb4f041b800641d5e2c4.zip
Details
- new error message for "attempt to assign to const variable" - note in the manual about compatibility options - comments - small changes in 'read_line' and 'pushstr'
-rw-r--r--liolib.c10
-rw-r--r--lobject.c4
-rw-r--r--lparser.c2
-rw-r--r--lstate.h16
-rw-r--r--luaconf.h14
-rw-r--r--manual/manual.of13
-rw-r--r--testes/constructs.lua6
-rw-r--r--testes/locals.lua1
-rw-r--r--testes/strings.lua3
9 files changed, 46 insertions, 23 deletions
diff --git a/liolib.c b/liolib.c
index fa6a0939..1484676d 100644
--- a/liolib.c
+++ b/liolib.c
@@ -504,17 +504,17 @@ static int test_eof (lua_State *L, FILE *f) {
504 504
505static int read_line (lua_State *L, FILE *f, int chop) { 505static int read_line (lua_State *L, FILE *f, int chop) {
506 luaL_Buffer b; 506 luaL_Buffer b;
507 int c = '\0'; 507 int c;
508 luaL_buffinit(L, &b); 508 luaL_buffinit(L, &b);
509 while (c != EOF && c != '\n') { /* repeat until end of line */ 509 do { /* may need to read several chunks to get whole line */
510 char *buff = luaL_prepbuffer(&b); /* preallocate buffer */ 510 char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */
511 int i = 0; 511 int i = 0;
512 l_lockfile(f); /* no memory errors can happen inside the lock */ 512 l_lockfile(f); /* no memory errors can happen inside the lock */
513 while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n') 513 while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
514 buff[i++] = c; 514 buff[i++] = c; /* read up to end of line or buffer limit */
515 l_unlockfile(f); 515 l_unlockfile(f);
516 luaL_addsize(&b, i); 516 luaL_addsize(&b, i);
517 } 517 } while (c != EOF && c != '\n'); /* repeat until end of line */
518 if (!chop && c == '\n') /* want a newline and have one? */ 518 if (!chop && c == '\n') /* want a newline and have one? */
519 luaL_addchar(&b, c); /* add ending newline to result */ 519 luaL_addchar(&b, c); /* add ending newline to result */
520 luaL_pushresult(&b); /* close buffer */ 520 luaL_pushresult(&b); /* close buffer */
diff --git a/lobject.c b/lobject.c
index ce14059f..979a6889 100644
--- a/lobject.c
+++ b/lobject.c
@@ -419,9 +419,9 @@ typedef struct BuffFS {
419static void pushstr (BuffFS *buff, const char *str, size_t l) { 419static void pushstr (BuffFS *buff, const char *str, size_t l) {
420 lua_State *L = buff->L; 420 lua_State *L = buff->L;
421 setsvalue2s(L, L->top, luaS_newlstr(L, str, l)); 421 setsvalue2s(L, L->top, luaS_newlstr(L, str, l));
422 L->top++; 422 L->top++; /* may use one extra slot */
423 buff->pushed++; 423 buff->pushed++;
424 if (buff->pushed > 1 && L->top + 2 > L->stack_last) { 424 if (buff->pushed > 1 && L->top + 1 >= L->stack_last) {
425 luaV_concat(L, buff->pushed); /* join all partial results into one */ 425 luaV_concat(L, buff->pushed); /* join all partial results into one */
426 buff->pushed = 1; 426 buff->pushed = 1;
427 } 427 }
diff --git a/lparser.c b/lparser.c
index 7c23710a..045efd93 100644
--- a/lparser.c
+++ b/lparser.c
@@ -264,7 +264,7 @@ static void check_readonly (LexState *ls, expdesc *e) {
264 Vardesc *vardesc = getvardesc(ls->fs, e); 264 Vardesc *vardesc = getvardesc(ls->fs, e);
265 if (vardesc && vardesc->ro) { /* is variable local and const? */ 265 if (vardesc && vardesc->ro) { /* is variable local and const? */
266 const char *msg = luaO_pushfstring(ls->L, 266 const char *msg = luaO_pushfstring(ls->L,
267 "assignment to const variable '%s'", getstr(vardesc->name)); 267 "attempt to assign to const variable '%s'", getstr(vardesc->name));
268 luaK_semerror(ls, msg); /* error */ 268 luaK_semerror(ls, msg); /* error */
269 } 269 }
270} 270}
diff --git a/lstate.h b/lstate.h
index e35f8962..3bd52973 100644
--- a/lstate.h
+++ b/lstate.h
@@ -26,6 +26,22 @@
26** 'fixedgc': all objects that are not to be collected (currently 26** 'fixedgc': all objects that are not to be collected (currently
27** only small strings, such as reserved words). 27** only small strings, such as reserved words).
28** 28**
29** For the generational collector, some of these lists have marks for
30** generations. Each mark points to the first element in the list for
31** that particular generation; that generation goes until the next mark.
32**
33** 'allgc' -> 'survival': new objects;
34** 'survival' -> 'old': objects that survived one collection;
35** 'old' -> 'reallyold': objects that became old in last collection;
36** 'reallyold' -> NULL: objects old for more than one cycle.
37**
38** 'finobj' -> 'finobjsur': new objects marked for finalization;
39** 'finobjsur' -> 'finobjold': survived """";
40** 'finobjold' -> 'finobjrold': just old """";
41** 'finobjrold' -> NULL: really old """".
42*/
43
44/*
29** Moreover, there is another set of lists that control gray objects. 45** Moreover, there is another set of lists that control gray objects.
30** These lists are linked by fields 'gclist'. (All objects that 46** These lists are linked by fields 'gclist'. (All objects that
31** can become gray have such a field. The field is not the same 47** can become gray have such a field. The field is not the same
diff --git a/luaconf.h b/luaconf.h
index 66dca6bf..39840e39 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -344,8 +344,8 @@
344/* 344/*
345@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated 345@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
346** functions in the mathematical library. 346** functions in the mathematical library.
347** (These functions were already officially removed in 5.3, but 347** (These functions were already officially removed in 5.3;
348** nevertheless they are available by default there.) 348** nevertheless they are still available here.)
349*/ 349*/
350#define LUA_COMPAT_MATHLIB 350#define LUA_COMPAT_MATHLIB
351 351
@@ -353,23 +353,25 @@
353@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for 353@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
354** manipulating other integer types (lua_pushunsigned, lua_tounsigned, 354** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
355** luaL_checkint, luaL_checklong, etc.) 355** luaL_checkint, luaL_checklong, etc.)
356** (These macros were also officially removed in 5.3, but they are still
357** available here.)
356*/ 358*/
357#define LUA_COMPAT_APIINTCASTS 359#define LUA_COMPAT_APIINTCASTS
358 360
361
359/* 362/*
360@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod 363@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod
361** using '__lt'. 364** using '__lt'.
362*/ 365*/
363#define LUA_COMPAT_LT_LE 366#define LUA_COMPAT_LT_LE
364 367
365#endif /* } */
366
367
368 368
369/* 369/*
370@@ The following macros supply trivial compatibility for some 370@@ The following macros supply trivial compatibility for some
371** changes in the API. The macros themselves document how to 371** changes in the API. The macros themselves document how to
372** change your code to avoid using them. 372** change your code to avoid using them.
373** (Once more, these macros were officially removed in 5.3, but they are
374** still available here.)
373*/ 375*/
374#define lua_strlen(L,i) lua_rawlen(L, (i)) 376#define lua_strlen(L,i) lua_rawlen(L, (i))
375 377
@@ -378,6 +380,8 @@
378#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) 380#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
379#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) 381#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
380 382
383#endif /* } */
384
381/* }================================================================== */ 385/* }================================================================== */
382 386
383 387
diff --git a/manual/manual.of b/manual/manual.of
index 6cac8c6c..ff69cd2c 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -8774,10 +8774,18 @@ is a more portable solution.
8774 8774
8775Here we list the incompatibilities that you may find when moving a program 8775Here we list the incompatibilities that you may find when moving a program
8776from @N{Lua 5.3} to @N{Lua 5.4}. 8776from @N{Lua 5.3} to @N{Lua 5.4}.
8777
8777You can avoid some incompatibilities by compiling Lua with 8778You can avoid some incompatibilities by compiling Lua with
8778appropriate options (see file @id{luaconf.h}). 8779appropriate options (see file @id{luaconf.h}).
8779However, 8780However,
8780all these compatibility options will be removed in the future. 8781all these compatibility options will be removed in the future.
8782More often than not,
8783compatibility issues arise when these compatibility options
8784are removed.
8785So, whenever you have the chance,
8786you should try to test your code with a version of Lua compiled
8787with all compatibility options turned off.
8788That will ease transitions to newer versions of Lua.
8781 8789
8782Lua versions can always change the C API in ways that 8790Lua versions can always change the C API in ways that
8783do not imply source-code changes in a program, 8791do not imply source-code changes in a program,
@@ -8826,11 +8834,6 @@ In particular, the control variable never wraps around.
8826} 8834}
8827 8835
8828@item{ 8836@item{
8829When a coroutine finishes with an error,
8830its stack is unwound (to run any pending closing methods).
8831}
8832
8833@item{
8834A label for a @Rw{goto} cannot be declared where a label with the same 8837A label for a @Rw{goto} cannot be declared where a label with the same
8835name is visible, even if this other label is declared in an enclosing 8838name is visible, even if this other label is declared in an enclosing
8836block. 8839block.
diff --git a/testes/constructs.lua b/testes/constructs.lua
index b91e0979..fe4db2cb 100644
--- a/testes/constructs.lua
+++ b/testes/constructs.lua
@@ -215,7 +215,7 @@ do -- testing constants
215 checkload(prog, "unknown attribute 'XXX'") 215 checkload(prog, "unknown attribute 'XXX'")
216 216
217 checkload([[local <const> xxx = 20; xxx = 10]], 217 checkload([[local <const> xxx = 20; xxx = 10]],
218 ":1: assignment to const variable 'xxx'") 218 ":1: attempt to assign to const variable 'xxx'")
219 219
220 checkload([[ 220 checkload([[
221 local xx; 221 local xx;
@@ -225,12 +225,12 @@ do -- testing constants
225 local abc = xx + yyy + xxx; 225 local abc = xx + yyy + xxx;
226 return function () return function () xxx = yyy end end 226 return function () return function () xxx = yyy end end
227 end 227 end
228 ]], ":6: assignment to const variable 'xxx'") 228 ]], ":6: attempt to assign to const variable 'xxx'")
229 229
230 checkload([[ 230 checkload([[
231 local <toclose> x = nil 231 local <toclose> x = nil
232 x = io.open() 232 x = io.open()
233 ]], ":2: assignment to const variable 'x'") 233 ]], ":2: attempt to assign to const variable 'x'")
234end 234end
235 235
236f = [[ 236f = [[
diff --git a/testes/locals.lua b/testes/locals.lua
index c176f506..e59ab95a 100644
--- a/testes/locals.lua
+++ b/testes/locals.lua
@@ -452,7 +452,6 @@ do
452 end) 452 end)
453 assert(co() == 100) 453 assert(co() == 100)
454 local st, msg = pcall(co) 454 local st, msg = pcall(co)
455print(msg)
456 -- should get last error raised 455 -- should get last error raised
457 assert(not st and string.find(msg, "%w+%.%w+:%d+: XXX")) 456 assert(not st and string.find(msg, "%w+%.%w+:%d+: XXX"))
458end 457end
diff --git a/testes/strings.lua b/testes/strings.lua
index 3e32f2c4..1b2b570e 100644
--- a/testes/strings.lua
+++ b/testes/strings.lua
@@ -3,7 +3,8 @@
3 3
4print('testing strings and string library') 4print('testing strings and string library')
5 5
6local maxi, mini = math.maxinteger, math.mininteger 6local <const> maxi = math.maxinteger
7local <const> mini = math.mininteger
7 8
8 9
9local function checkerror (msg, f, ...) 10local function checkerror (msg, f, ...)