Browse Source

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'
pull/23/head
Roberto Ierusalimschy 6 years ago
parent
commit
b293ae0577
  1. 10
      liolib.c
  2. 4
      lobject.c
  3. 2
      lparser.c
  4. 16
      lstate.h
  5. 14
      luaconf.h
  6. 13
      manual/manual.of
  7. 6
      testes/constructs.lua
  8. 1
      testes/locals.lua
  9. 3
      testes/strings.lua

10
liolib.c

@ -504,17 +504,17 @@ static int test_eof (lua_State *L, FILE *f) {
static int read_line (lua_State *L, FILE *f, int chop) {
luaL_Buffer b;
int c = '\0';
int c;
luaL_buffinit(L, &b);
while (c != EOF && c != '\n') { /* repeat until end of line */
char *buff = luaL_prepbuffer(&b); /* preallocate buffer */
do { /* may need to read several chunks to get whole line */
char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */
int i = 0;
l_lockfile(f); /* no memory errors can happen inside the lock */
while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
buff[i++] = c;
buff[i++] = c; /* read up to end of line or buffer limit */
l_unlockfile(f);
luaL_addsize(&b, i);
}
} while (c != EOF && c != '\n'); /* repeat until end of line */
if (!chop && c == '\n') /* want a newline and have one? */
luaL_addchar(&b, c); /* add ending newline to result */
luaL_pushresult(&b); /* close buffer */

4
lobject.c

@ -419,9 +419,9 @@ typedef struct BuffFS {
static void pushstr (BuffFS *buff, const char *str, size_t l) {
lua_State *L = buff->L;
setsvalue2s(L, L->top, luaS_newlstr(L, str, l));
L->top++;
L->top++; /* may use one extra slot */
buff->pushed++;
if (buff->pushed > 1 && L->top + 2 > L->stack_last) {
if (buff->pushed > 1 && L->top + 1 >= L->stack_last) {
luaV_concat(L, buff->pushed); /* join all partial results into one */
buff->pushed = 1;
}

2
lparser.c

@ -264,7 +264,7 @@ static void check_readonly (LexState *ls, expdesc *e) {
Vardesc *vardesc = getvardesc(ls->fs, e);
if (vardesc && vardesc->ro) { /* is variable local and const? */
const char *msg = luaO_pushfstring(ls->L,
"assignment to const variable '%s'", getstr(vardesc->name));
"attempt to assign to const variable '%s'", getstr(vardesc->name));
luaK_semerror(ls, msg); /* error */
}
}

16
lstate.h

@ -26,6 +26,22 @@
** 'fixedgc': all objects that are not to be collected (currently
** only small strings, such as reserved words).
**
** For the generational collector, some of these lists have marks for
** generations. Each mark points to the first element in the list for
** that particular generation; that generation goes until the next mark.
**
** 'allgc' -> 'survival': new objects;
** 'survival' -> 'old': objects that survived one collection;
** 'old' -> 'reallyold': objects that became old in last collection;
** 'reallyold' -> NULL: objects old for more than one cycle.
**
** 'finobj' -> 'finobjsur': new objects marked for finalization;
** 'finobjsur' -> 'finobjold': survived """";
** 'finobjold' -> 'finobjrold': just old """";
** 'finobjrold' -> NULL: really old """".
*/
/*
** Moreover, there is another set of lists that control gray objects.
** These lists are linked by fields 'gclist'. (All objects that
** can become gray have such a field. The field is not the same

14
luaconf.h

@ -344,8 +344,8 @@
/*
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
** functions in the mathematical library.
** (These functions were already officially removed in 5.3, but
** nevertheless they are available by default there.)
** (These functions were already officially removed in 5.3;
** nevertheless they are still available here.)
*/
#define LUA_COMPAT_MATHLIB
@ -353,23 +353,25 @@
@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
** luaL_checkint, luaL_checklong, etc.)
** (These macros were also officially removed in 5.3, but they are still
** available here.)
*/
#define LUA_COMPAT_APIINTCASTS
/*
@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod
** using '__lt'.
*/
#define LUA_COMPAT_LT_LE
#endif /* } */
/*
@@ The following macros supply trivial compatibility for some
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
** (Once more, these macros were officially removed in 5.3, but they are
** still available here.)
*/
#define lua_strlen(L,i) lua_rawlen(L, (i))
@ -378,6 +380,8 @@
#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
#endif /* } */
/* }================================================================== */

13
manual/manual.of

@ -8774,10 +8774,18 @@ is a more portable solution.
Here we list the incompatibilities that you may find when moving a program
from @N{Lua 5.3} to @N{Lua 5.4}.
You can avoid some incompatibilities by compiling Lua with
appropriate options (see file @id{luaconf.h}).
However,
all these compatibility options will be removed in the future.
More often than not,
compatibility issues arise when these compatibility options
are removed.
So, whenever you have the chance,
you should try to test your code with a version of Lua compiled
with all compatibility options turned off.
That will ease transitions to newer versions of Lua.
Lua versions can always change the C API in ways that
do not imply source-code changes in a program,
@ -8825,11 +8833,6 @@ over integers changed in some details.
In particular, the control variable never wraps around.
}
@item{
When a coroutine finishes with an error,
its stack is unwound (to run any pending closing methods).
}
@item{
A label for a @Rw{goto} cannot be declared where a label with the same
name is visible, even if this other label is declared in an enclosing

6
testes/constructs.lua

@ -215,7 +215,7 @@ do -- testing constants
checkload(prog, "unknown attribute 'XXX'")
checkload([[local <const> xxx = 20; xxx = 10]],
":1: assignment to const variable 'xxx'")
":1: attempt to assign to const variable 'xxx'")
checkload([[
local xx;
@ -225,12 +225,12 @@ do -- testing constants
local abc = xx + yyy + xxx;
return function () return function () xxx = yyy end end
end
]], ":6: assignment to const variable 'xxx'")
]], ":6: attempt to assign to const variable 'xxx'")
checkload([[
local <toclose> x = nil
x = io.open()
]], ":2: assignment to const variable 'x'")
]], ":2: attempt to assign to const variable 'x'")
end
f = [[

1
testes/locals.lua

@ -452,7 +452,6 @@ do
end)
assert(co() == 100)
local st, msg = pcall(co)
print(msg)
-- should get last error raised
assert(not st and string.find(msg, "%w+%.%w+:%d+: XXX"))
end

3
testes/strings.lua

@ -3,7 +3,8 @@
print('testing strings and string library')
local maxi, mini = math.maxinteger, math.mininteger
local <const> maxi = math.maxinteger
local <const> mini = math.mininteger
local function checkerror (msg, f, ...)

Loading…
Cancel
Save