Details
Comments, small changes in the manual, an extra test for errors in error handling, small changes in tests.
This commit is contained in:
@@ -512,7 +512,7 @@ static void initbuff (lua_State *L, BuffFS *buff) {
|
|||||||
static void pushbuff (lua_State *L, void *ud) {
|
static void pushbuff (lua_State *L, void *ud) {
|
||||||
BuffFS *buff = cast(BuffFS*, ud);
|
BuffFS *buff = cast(BuffFS*, ud);
|
||||||
switch (buff->err) {
|
switch (buff->err) {
|
||||||
case 1:
|
case 1: /* memory error */
|
||||||
luaD_throw(L, LUA_ERRMEM);
|
luaD_throw(L, LUA_ERRMEM);
|
||||||
break;
|
break;
|
||||||
case 2: /* length overflow: Add "..." at the end of result */
|
case 2: /* length overflow: Add "..." at the end of result */
|
||||||
@@ -523,7 +523,7 @@ static void pushbuff (lua_State *L, void *ud) {
|
|||||||
buff->blen += 3;
|
buff->blen += 3;
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
default: { /* no errors */
|
default: { /* no errors, but it can raise one creating the new string */
|
||||||
TString *ts = luaS_newlstr(L, buff->b, buff->blen);
|
TString *ts = luaS_newlstr(L, buff->b, buff->blen);
|
||||||
setsvalue2s(L, L->top.p, ts);
|
setsvalue2s(L, L->top.p, ts);
|
||||||
L->top.p++;
|
L->top.p++;
|
||||||
|
|||||||
@@ -6347,7 +6347,7 @@ Opens all standard Lua libraries into the given state.
|
|||||||
@APIEntry{void luaL_openselectedlibs (lua_State *L, int load, int preload);|
|
@APIEntry{void luaL_openselectedlibs (lua_State *L, int load, int preload);|
|
||||||
@apii{0,0,e}
|
@apii{0,0,e}
|
||||||
|
|
||||||
Opens (loads) and preloads selected libraries into the state @id{L}.
|
Opens (loads) and preloads selected standard libraries into the state @id{L}.
|
||||||
(To @emph{preload} means to add
|
(To @emph{preload} means to add
|
||||||
the library loader into the table @Lid{package.preload},
|
the library loader into the table @Lid{package.preload},
|
||||||
so that the library can be required later by the program.
|
so that the library can be required later by the program.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ end
|
|||||||
-- test error message with no extra info
|
-- test error message with no extra info
|
||||||
assert(doit("error('hi', 0)") == 'hi')
|
assert(doit("error('hi', 0)") == 'hi')
|
||||||
|
|
||||||
-- test error message with no info
|
-- test nil error message
|
||||||
assert(doit("error()") == nil)
|
assert(doit("error()") == nil)
|
||||||
|
|
||||||
|
|
||||||
@@ -555,7 +555,7 @@ if not _soft then
|
|||||||
|
|
||||||
-- error in error handling
|
-- error in error handling
|
||||||
local res, msg = xpcall(error, error)
|
local res, msg = xpcall(error, error)
|
||||||
assert(not res and type(msg) == 'string')
|
assert(not res and msg == 'error in error handling')
|
||||||
print('+')
|
print('+')
|
||||||
|
|
||||||
local function f (x)
|
local function f (x)
|
||||||
@@ -586,6 +586,27 @@ if not _soft then
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
do -- errors in error handle that not necessarily go forever
|
||||||
|
local function err (n) -- function to be used as message handler
|
||||||
|
-- generate an error unless n is zero, so that there is a limited
|
||||||
|
-- loop of errors
|
||||||
|
if type(n) ~= "number" then -- some other error?
|
||||||
|
return n -- report it
|
||||||
|
elseif n == 0 then
|
||||||
|
return "END" -- that will be the final message
|
||||||
|
else error(n - 1) -- does the loop
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local res, msg = xpcall(error, err, 170)
|
||||||
|
assert(not res and msg == "END")
|
||||||
|
|
||||||
|
-- too many levels
|
||||||
|
local res, msg = xpcall(error, err, 300)
|
||||||
|
assert(not res and msg == "C stack overflow")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
do
|
do
|
||||||
-- non string messages
|
-- non string messages
|
||||||
local t = {}
|
local t = {}
|
||||||
|
|||||||
@@ -310,8 +310,11 @@ checkprogout("ZYX)\nXYZ)\n")
|
|||||||
-- bug since 5.2: finalizer called when closing a state could
|
-- bug since 5.2: finalizer called when closing a state could
|
||||||
-- subvert finalization order
|
-- subvert finalization order
|
||||||
prepfile[[
|
prepfile[[
|
||||||
-- should be called last
|
-- ensure tables will be collected only at the end of the program
|
||||||
|
collectgarbage"stop"
|
||||||
|
|
||||||
print("creating 1")
|
print("creating 1")
|
||||||
|
-- this finalizer should be called last
|
||||||
setmetatable({}, {__gc = function () print(1) end})
|
setmetatable({}, {__gc = function () print(1) end})
|
||||||
|
|
||||||
print("creating 2")
|
print("creating 2")
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ do
|
|||||||
__index = function (_,k) pos1 = k end,
|
__index = function (_,k) pos1 = k end,
|
||||||
__newindex = function (_,k) pos2 = k; error() end, })
|
__newindex = function (_,k) pos2 = k; error() end, })
|
||||||
local st, msg = pcall(table.move, a, f, e, t)
|
local st, msg = pcall(table.move, a, f, e, t)
|
||||||
assert(not st and not msg and pos1 == x and pos2 == y)
|
assert(not st and pos1 == x and pos2 == y)
|
||||||
end
|
end
|
||||||
checkmove(1, maxI, 0, 1, 0)
|
checkmove(1, maxI, 0, 1, 0)
|
||||||
checkmove(0, maxI - 1, 1, maxI - 1, maxI)
|
checkmove(0, maxI - 1, 1, maxI - 1, maxI)
|
||||||
|
|||||||
Reference in New Issue
Block a user