diff options
-rw-r--r-- | lobject.c | 8 | ||||
-rw-r--r-- | manual/manual.of | 2 | ||||
-rw-r--r-- | testes/errors.lua | 25 | ||||
-rw-r--r-- | testes/main.lua | 5 | ||||
-rw-r--r-- | testes/sort.lua | 2 |
5 files changed, 33 insertions, 9 deletions
@@ -247,7 +247,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { | |||
247 | nosigdig++; | 247 | nosigdig++; |
248 | else if (++sigdig <= MAXSIGDIG) /* can read it without overflow? */ | 248 | else if (++sigdig <= MAXSIGDIG) /* can read it without overflow? */ |
249 | r = (r * l_mathop(16.0)) + luaO_hexavalue(*s); | 249 | r = (r * l_mathop(16.0)) + luaO_hexavalue(*s); |
250 | else e++; /* too many digits; ignore, but still count for exponent */ | 250 | else e++; /* too many digits; ignore, but still count for exponent */ |
251 | if (hasdot) e--; /* decimal digit? correct exponent */ | 251 | if (hasdot) e--; /* decimal digit? correct exponent */ |
252 | } | 252 | } |
253 | else break; /* neither a dot nor a digit */ | 253 | else break; /* neither a dot nor a digit */ |
@@ -512,18 +512,18 @@ static void initbuff (lua_State *L, BuffFS *buff) { | |||
512 | static void pushbuff (lua_State *L, void *ud) { | 512 | static void pushbuff (lua_State *L, void *ud) { |
513 | BuffFS *buff = cast(BuffFS*, ud); | 513 | BuffFS *buff = cast(BuffFS*, ud); |
514 | switch (buff->err) { | 514 | switch (buff->err) { |
515 | case 1: | 515 | case 1: /* memory error */ |
516 | luaD_throw(L, LUA_ERRMEM); | 516 | luaD_throw(L, LUA_ERRMEM); |
517 | break; | 517 | break; |
518 | case 2: /* length overflow: Add "..." at the end of result */ | 518 | case 2: /* length overflow: Add "..." at the end of result */ |
519 | if (buff->buffsize - buff->blen < 3) | 519 | if (buff->buffsize - buff->blen < 3) |
520 | strcpy(buff->b + buff->blen - 3, "..."); /* 'blen' must be > 3 */ | 520 | strcpy(buff->b + buff->blen - 3, "..."); /* 'blen' must be > 3 */ |
521 | else { /* there is enough space left for the "..." */ | 521 | else { /* there is enough space left for the "..." */ |
522 | strcpy(buff->b + buff->blen, "..."); | 522 | strcpy(buff->b + buff->blen, "..."); |
523 | buff->blen += 3; | 523 | buff->blen += 3; |
524 | } | 524 | } |
525 | /* FALLTHROUGH */ | 525 | /* FALLTHROUGH */ |
526 | default: { /* no errors */ | 526 | default: { /* no errors, but it can raise one creating the new string */ |
527 | TString *ts = luaS_newlstr(L, buff->b, buff->blen); | 527 | TString *ts = luaS_newlstr(L, buff->b, buff->blen); |
528 | setsvalue2s(L, L->top.p, ts); | 528 | setsvalue2s(L, L->top.p, ts); |
529 | L->top.p++; | 529 | L->top.p++; |
diff --git a/manual/manual.of b/manual/manual.of index 274799e3..a55c7b49 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -6347,7 +6347,7 @@ Opens all standard Lua libraries into the given state. | |||
6347 | @APIEntry{void luaL_openselectedlibs (lua_State *L, int load, int preload);| | 6347 | @APIEntry{void luaL_openselectedlibs (lua_State *L, int load, int preload);| |
6348 | @apii{0,0,e} | 6348 | @apii{0,0,e} |
6349 | 6349 | ||
6350 | Opens (loads) and preloads selected libraries into the state @id{L}. | 6350 | Opens (loads) and preloads selected standard libraries into the state @id{L}. |
6351 | (To @emph{preload} means to add | 6351 | (To @emph{preload} means to add |
6352 | the library loader into the table @Lid{package.preload}, | 6352 | the library loader into the table @Lid{package.preload}, |
6353 | so that the library can be required later by the program. | 6353 | so that the library can be required later by the program. |
diff --git a/testes/errors.lua b/testes/errors.lua index 027e1b03..adc111fd 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
@@ -45,7 +45,7 @@ end | |||
45 | -- test error message with no extra info | 45 | -- test error message with no extra info |
46 | assert(doit("error('hi', 0)") == 'hi') | 46 | assert(doit("error('hi', 0)") == 'hi') |
47 | 47 | ||
48 | -- test error message with no info | 48 | -- test nil error message |
49 | assert(doit("error()") == nil) | 49 | assert(doit("error()") == nil) |
50 | 50 | ||
51 | 51 | ||
@@ -555,7 +555,7 @@ if not _soft then | |||
555 | 555 | ||
556 | -- error in error handling | 556 | -- error in error handling |
557 | local res, msg = xpcall(error, error) | 557 | local res, msg = xpcall(error, error) |
558 | assert(not res and type(msg) == 'string') | 558 | assert(not res and msg == 'error in error handling') |
559 | print('+') | 559 | print('+') |
560 | 560 | ||
561 | local function f (x) | 561 | local function f (x) |
@@ -586,6 +586,27 @@ if not _soft then | |||
586 | end | 586 | end |
587 | 587 | ||
588 | 588 | ||
589 | do -- errors in error handle that not necessarily go forever | ||
590 | local function err (n) -- function to be used as message handler | ||
591 | -- generate an error unless n is zero, so that there is a limited | ||
592 | -- loop of errors | ||
593 | if type(n) ~= "number" then -- some other error? | ||
594 | return n -- report it | ||
595 | elseif n == 0 then | ||
596 | return "END" -- that will be the final message | ||
597 | else error(n - 1) -- does the loop | ||
598 | end | ||
599 | end | ||
600 | |||
601 | local res, msg = xpcall(error, err, 170) | ||
602 | assert(not res and msg == "END") | ||
603 | |||
604 | -- too many levels | ||
605 | local res, msg = xpcall(error, err, 300) | ||
606 | assert(not res and msg == "C stack overflow") | ||
607 | end | ||
608 | |||
609 | |||
589 | do | 610 | do |
590 | -- non string messages | 611 | -- non string messages |
591 | local t = {} | 612 | local t = {} |
diff --git a/testes/main.lua b/testes/main.lua index 1aa7b217..e0e9cbe8 100644 --- a/testes/main.lua +++ b/testes/main.lua | |||
@@ -310,8 +310,11 @@ checkprogout("ZYX)\nXYZ)\n") | |||
310 | -- bug since 5.2: finalizer called when closing a state could | 310 | -- bug since 5.2: finalizer called when closing a state could |
311 | -- subvert finalization order | 311 | -- subvert finalization order |
312 | prepfile[[ | 312 | prepfile[[ |
313 | -- should be called last | 313 | -- ensure tables will be collected only at the end of the program |
314 | collectgarbage"stop" | ||
315 | |||
314 | print("creating 1") | 316 | print("creating 1") |
317 | -- this finalizer should be called last | ||
315 | setmetatable({}, {__gc = function () print(1) end}) | 318 | setmetatable({}, {__gc = function () print(1) end}) |
316 | 319 | ||
317 | print("creating 2") | 320 | print("creating 2") |
diff --git a/testes/sort.lua b/testes/sort.lua index 965e1534..290b199e 100644 --- a/testes/sort.lua +++ b/testes/sort.lua | |||
@@ -199,7 +199,7 @@ do | |||
199 | __index = function (_,k) pos1 = k end, | 199 | __index = function (_,k) pos1 = k end, |
200 | __newindex = function (_,k) pos2 = k; error() end, }) | 200 | __newindex = function (_,k) pos2 = k; error() end, }) |
201 | local st, msg = pcall(table.move, a, f, e, t) | 201 | local st, msg = pcall(table.move, a, f, e, t) |
202 | assert(not st and not msg and pos1 == x and pos2 == y) | 202 | assert(not st and pos1 == x and pos2 == y) |
203 | end | 203 | end |
204 | checkmove(1, maxI, 0, 1, 0) | 204 | checkmove(1, maxI, 0, 1, 0) |
205 | checkmove(0, maxI - 1, 1, maxI - 1, maxI) | 205 | checkmove(0, maxI - 1, 1, maxI - 1, maxI) |