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'
This commit is contained in:
10
liolib.c
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) {
|
static int read_line (lua_State *L, FILE *f, int chop) {
|
||||||
luaL_Buffer b;
|
luaL_Buffer b;
|
||||||
int c = '\0';
|
int c;
|
||||||
luaL_buffinit(L, &b);
|
luaL_buffinit(L, &b);
|
||||||
while (c != EOF && c != '\n') { /* repeat until end of line */
|
do { /* may need to read several chunks to get whole line */
|
||||||
char *buff = luaL_prepbuffer(&b); /* preallocate buffer */
|
char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */
|
||||||
int i = 0;
|
int i = 0;
|
||||||
l_lockfile(f); /* no memory errors can happen inside the lock */
|
l_lockfile(f); /* no memory errors can happen inside the lock */
|
||||||
while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
|
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);
|
l_unlockfile(f);
|
||||||
luaL_addsize(&b, i);
|
luaL_addsize(&b, i);
|
||||||
}
|
} while (c != EOF && c != '\n'); /* repeat until end of line */
|
||||||
if (!chop && c == '\n') /* want a newline and have one? */
|
if (!chop && c == '\n') /* want a newline and have one? */
|
||||||
luaL_addchar(&b, c); /* add ending newline to result */
|
luaL_addchar(&b, c); /* add ending newline to result */
|
||||||
luaL_pushresult(&b); /* close buffer */
|
luaL_pushresult(&b); /* close buffer */
|
||||||
|
|||||||
@@ -419,9 +419,9 @@ typedef struct BuffFS {
|
|||||||
static void pushstr (BuffFS *buff, const char *str, size_t l) {
|
static void pushstr (BuffFS *buff, const char *str, size_t l) {
|
||||||
lua_State *L = buff->L;
|
lua_State *L = buff->L;
|
||||||
setsvalue2s(L, L->top, luaS_newlstr(L, str, l));
|
setsvalue2s(L, L->top, luaS_newlstr(L, str, l));
|
||||||
L->top++;
|
L->top++; /* may use one extra slot */
|
||||||
buff->pushed++;
|
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 */
|
luaV_concat(L, buff->pushed); /* join all partial results into one */
|
||||||
buff->pushed = 1;
|
buff->pushed = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ static void check_readonly (LexState *ls, expdesc *e) {
|
|||||||
Vardesc *vardesc = getvardesc(ls->fs, e);
|
Vardesc *vardesc = getvardesc(ls->fs, e);
|
||||||
if (vardesc && vardesc->ro) { /* is variable local and const? */
|
if (vardesc && vardesc->ro) { /* is variable local and const? */
|
||||||
const char *msg = luaO_pushfstring(ls->L,
|
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 */
|
luaK_semerror(ls, msg); /* error */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
lstate.h
16
lstate.h
@@ -26,6 +26,22 @@
|
|||||||
** 'fixedgc': all objects that are not to be collected (currently
|
** 'fixedgc': all objects that are not to be collected (currently
|
||||||
** only small strings, such as reserved words).
|
** 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.
|
** Moreover, there is another set of lists that control gray objects.
|
||||||
** These lists are linked by fields 'gclist'. (All objects that
|
** These lists are linked by fields 'gclist'. (All objects that
|
||||||
** can become gray have such a field. The field is not the same
|
** can become gray have such a field. The field is not the same
|
||||||
|
|||||||
14
luaconf.h
14
luaconf.h
@@ -344,8 +344,8 @@
|
|||||||
/*
|
/*
|
||||||
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
|
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
|
||||||
** functions in the mathematical library.
|
** functions in the mathematical library.
|
||||||
** (These functions were already officially removed in 5.3, but
|
** (These functions were already officially removed in 5.3;
|
||||||
** nevertheless they are available by default there.)
|
** nevertheless they are still available here.)
|
||||||
*/
|
*/
|
||||||
#define LUA_COMPAT_MATHLIB
|
#define LUA_COMPAT_MATHLIB
|
||||||
|
|
||||||
@@ -353,23 +353,25 @@
|
|||||||
@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
|
@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
|
||||||
** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
|
** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
|
||||||
** luaL_checkint, luaL_checklong, etc.)
|
** luaL_checkint, luaL_checklong, etc.)
|
||||||
|
** (These macros were also officially removed in 5.3, but they are still
|
||||||
|
** available here.)
|
||||||
*/
|
*/
|
||||||
#define LUA_COMPAT_APIINTCASTS
|
#define LUA_COMPAT_APIINTCASTS
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod
|
@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod
|
||||||
** using '__lt'.
|
** using '__lt'.
|
||||||
*/
|
*/
|
||||||
#define LUA_COMPAT_LT_LE
|
#define LUA_COMPAT_LT_LE
|
||||||
|
|
||||||
#endif /* } */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ The following macros supply trivial compatibility for some
|
@@ The following macros supply trivial compatibility for some
|
||||||
** changes in the API. The macros themselves document how to
|
** changes in the API. The macros themselves document how to
|
||||||
** change your code to avoid using them.
|
** 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))
|
#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_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
|
||||||
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
|
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
|
||||||
|
|
||||||
|
#endif /* } */
|
||||||
|
|
||||||
/* }================================================================== */
|
/* }================================================================== */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8774,10 +8774,18 @@ is a more portable solution.
|
|||||||
|
|
||||||
Here we list the incompatibilities that you may find when moving a program
|
Here we list the incompatibilities that you may find when moving a program
|
||||||
from @N{Lua 5.3} to @N{Lua 5.4}.
|
from @N{Lua 5.3} to @N{Lua 5.4}.
|
||||||
|
|
||||||
You can avoid some incompatibilities by compiling Lua with
|
You can avoid some incompatibilities by compiling Lua with
|
||||||
appropriate options (see file @id{luaconf.h}).
|
appropriate options (see file @id{luaconf.h}).
|
||||||
However,
|
However,
|
||||||
all these compatibility options will be removed in the future.
|
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
|
Lua versions can always change the C API in ways that
|
||||||
do not imply source-code changes in a program,
|
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.
|
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{
|
@item{
|
||||||
A label for a @Rw{goto} cannot be declared where a label with the same
|
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
|
name is visible, even if this other label is declared in an enclosing
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ do -- testing constants
|
|||||||
checkload(prog, "unknown attribute 'XXX'")
|
checkload(prog, "unknown attribute 'XXX'")
|
||||||
|
|
||||||
checkload([[local <const> xxx = 20; xxx = 10]],
|
checkload([[local <const> xxx = 20; xxx = 10]],
|
||||||
":1: assignment to const variable 'xxx'")
|
":1: attempt to assign to const variable 'xxx'")
|
||||||
|
|
||||||
checkload([[
|
checkload([[
|
||||||
local xx;
|
local xx;
|
||||||
@@ -225,12 +225,12 @@ do -- testing constants
|
|||||||
local abc = xx + yyy + xxx;
|
local abc = xx + yyy + xxx;
|
||||||
return function () return function () xxx = yyy end end
|
return function () return function () xxx = yyy end end
|
||||||
end
|
end
|
||||||
]], ":6: assignment to const variable 'xxx'")
|
]], ":6: attempt to assign to const variable 'xxx'")
|
||||||
|
|
||||||
checkload([[
|
checkload([[
|
||||||
local <toclose> x = nil
|
local <toclose> x = nil
|
||||||
x = io.open()
|
x = io.open()
|
||||||
]], ":2: assignment to const variable 'x'")
|
]], ":2: attempt to assign to const variable 'x'")
|
||||||
end
|
end
|
||||||
|
|
||||||
f = [[
|
f = [[
|
||||||
|
|||||||
@@ -452,7 +452,6 @@ do
|
|||||||
end)
|
end)
|
||||||
assert(co() == 100)
|
assert(co() == 100)
|
||||||
local st, msg = pcall(co)
|
local st, msg = pcall(co)
|
||||||
print(msg)
|
|
||||||
-- should get last error raised
|
-- should get last error raised
|
||||||
assert(not st and string.find(msg, "%w+%.%w+:%d+: XXX"))
|
assert(not st and string.find(msg, "%w+%.%w+:%d+: XXX"))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
print('testing strings and string library')
|
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, ...)
|
local function checkerror (msg, f, ...)
|
||||||
|
|||||||
Reference in New Issue
Block a user