History

Lua 5.1.3-rc1

Lua Team committed 18 years ago

Commit ea97e791 parent 4d388a360 files · +732 −439Browse files

Showing the changes to src (54 of 60 files). Show all

Unified · Split

54 files
  1. src/Makefile +1 −2
  2. src/lapi.c +7 −2
  3. src/lapi.h +1 −1
  4. src/lauxlib.c +2 −2
  5. src/lauxlib.h +1 −1
  6. src/lbaselib.c +41 −32
  7. src/lcode.c +2 −2
  8. src/lcode.h +1 −1
  9. src/ldblib.c +1 −1
  10. src/ldebug.c +3 −3
  11. src/ldebug.h +1 −1
  12. src/ldo.c +12 −10
  13. src/ldo.h +1 −1
  14. src/ldump.c +1 −1
  15. src/lfunc.c +1 −1
  16. src/lfunc.h +1 −1
  17. src/lgc.c +1 −1
  18. src/lgc.h +1 −1
  19. src/linit.c +1 −1
  20. src/liolib.c +7 −5
  21. src/llex.c +1 −1
  22. src/llex.h +1 −1
  23. src/llimits.h +1 −1
  24. src/lmathlib.c +1 −1
  25. src/lmem.c +1 −1
  26. src/lmem.h +1 −1
  27. src/loadlib.c +1 −1
  28. src/lobject.c +1 −1
  29. src/lobject.h +1 −1
  30. src/lopcodes.c +1 −1
  31. src/lopcodes.h +1 −1
  32. src/loslib.c +1 −1
  33. src/lparser.c +3 −1
  34. src/lparser.h +1 −1
  35. src/lstate.c +3 −3
  36. src/lstate.h +2 −1
  37. src/lstring.c +1 −1
  38. src/lstring.h +1 −1
  39. src/lstrlib.c +5 −5
  40. src/ltable.c +3 −3
  41. src/ltable.h +1 −1
  42. src/ltablib.c +3 −2
  43. src/ltm.c +1 −1
  44. src/ltm.h +1 −1
  45. src/lua.c +4 −2
  46. src/lua.h +7 −4
  47. src/luaconf.h +3 −2
  48. src/lualib.h +1 −1
  49. src/lundump.c +1 −1
  50. src/lundump.h +1 −1
  51. src/lvm.c +4 −6
  52. src/lvm.h +1 −1
  53. src/lzio.c +1 −1
  54. src/lzio.h +1 −1
src/Makefile+1−2
@@ -148,8 +148,7 @@ llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ · 147 unmodified lines
148148 lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
149149 lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
150150 ltm.h lzio.h lmem.h ldo.h
151−loadlib.o: loadlib.c lauxlib.h lua.h luaconf.h lobject.h llimits.h \
152− lualib.h
151+loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
153152 lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \
154153 ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h
155154 lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
src/lapi.c+7−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lapi.c,v 2.55 2006/06/07 12:37:17 roberto Exp $
2+** $Id: lapi.c,v 2.55.1.3 2008/01/03 15:20:39 roberto Exp $
33 ** Lua API
44 ** See Copyright Notice in lua.h
55 */
@@ -123,6 +123,11 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { · 117 unmodified lines
123123 }
124124
125125
126+LUA_API void lua_setlevel (lua_State *from, lua_State *to) {
127+ to->nCcalls = from->nCcalls;
128+}
129+
130+
126131 LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
127132 lua_CFunction old;
128133 lua_lock(L);
@@ -749,7 +754,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) { · 620 unmodified lines
749754 res = 0;
750755 break;
751756 }
752− luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
757+ if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
753758 L->top--;
754759 lua_unlock(L);
755760 return res;
src/lapi.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lapi.h,v 2.2 2005/04/25 19:24:10 roberto Exp $
2+** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Auxiliary functions from Lua API
44 ** See Copyright Notice in lua.h
55 */
src/lauxlib.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.c,v 1.159 2006/03/21 19:31:09 roberto Exp $
2+** $Id: lauxlib.c,v 1.159.1.2 2008/01/17 14:04:41 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -244,7 +244,7 @@ LUALIB_API void luaI_openlib (lua_State *L, const char *libname, · 238 unmodified lines
244244 if (libname) {
245245 int size = libsize(l);
246246 /* check whether lib already exists */
247− luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size);
247+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
248248 lua_getfield(L, -1, libname); /* get _LOADED[libname] */
249249 if (!lua_istable(L, -1)) { /* not found? */
250250 lua_pop(L, 1); /* remove previous result */
src/lauxlib.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.h,v 1.88 2006/04/12 20:31:15 roberto Exp $
2+** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
src/lbaselib.c+41−32
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.191a 2006/06/02 15:34:00 roberto Exp $
2+** $Id: lbaselib.c,v 1.191.1.3 2008/01/03 15:20:39 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -477,15 +477,52 @@ static const luaL_Reg base_funcs[] = { · 471 unmodified lines
477477 ** =======================================================
478478 */
479479
480+#define CO_RUN 0 /* running */
481+#define CO_SUS 1 /* suspended */
482+#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */
483+#define CO_DEAD 3
484+
485+static const char *const statnames[] =
486+ {"running", "suspended", "normal", "dead"};
487+
488+static int costatus (lua_State *L, lua_State *co) {
489+ if (L == co) return CO_RUN;
490+ switch (lua_status(co)) {
491+ case LUA_YIELD:
492+ return CO_SUS;
493+ case 0: {
494+ lua_Debug ar;
495+ if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
496+ return CO_NOR; /* it is running */
497+ else if (lua_gettop(co) == 0)
498+ return CO_DEAD;
499+ else
500+ return CO_SUS; /* initial state */
501+ }
502+ default: /* some error occured */
503+ return CO_DEAD;
504+ }
505+}
506+
507+
508+static int luaB_costatus (lua_State *L) {
509+ lua_State *co = lua_tothread(L, 1);
510+ luaL_argcheck(L, co, 1, "coroutine expected");
511+ lua_pushstring(L, statnames[costatus(L, co)]);
512+ return 1;
513+}
514+
515+
480516 static int auxresume (lua_State *L, lua_State *co, int narg) {
481− int status;
517+ int status = costatus(L, co);
482518 if (!lua_checkstack(co, narg))
483519 luaL_error(L, "too many arguments to resume");
484− if (lua_status(co) == 0 && lua_gettop(co) == 0) {
485− lua_pushliteral(L, "cannot resume dead coroutine");
520+ if (status != CO_SUS) {
521+ lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]);
486522 return -1; /* error flag */
487523 }
488524 lua_xmove(L, co, narg);
525+ lua_setlevel(L, co);
489526 status = lua_resume(co, narg);
490527 if (status == 0 || status == LUA_YIELD) {
491528 int nres = lua_gettop(co);
@@ -556,34 +593,6 @@ static int luaB_yield (lua_State *L) { · 64 unmodified lines
556593 }
557594
558595
559−static int luaB_costatus (lua_State *L) {
560− lua_State *co = lua_tothread(L, 1);
561− luaL_argcheck(L, co, 1, "coroutine expected");
562− if (L == co) lua_pushliteral(L, "running");
563− else {
564− switch (lua_status(co)) {
565− case LUA_YIELD:
566− lua_pushliteral(L, "suspended");
567− break;
568− case 0: {
569− lua_Debug ar;
570− if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
571− lua_pushliteral(L, "normal"); /* it is running */
572− else if (lua_gettop(co) == 0)
573− lua_pushliteral(L, "dead");
574− else
575− lua_pushliteral(L, "suspended"); /* initial state */
576− break;
577− }
578− default: /* some error occured */
579− lua_pushliteral(L, "dead");
580− break;
581− }
582− }
583− return 1;
584−}
585−
586−
587596 static int luaB_corunning (lua_State *L) {
588597 if (lua_pushthread(L))
589598 return 0; /* main thread is not a coroutine */
src/lcode.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.c,v 2.25a 2006/03/21 19:28:49 roberto Exp $
2+** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -699,7 +699,7 @@ void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { · 693 unmodified lines
699699 e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
700700 switch (op) {
701701 case OPR_MINUS: {
702− if (e->k == VK)
702+ if (!isnumeral(e))
703703 luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */
704704 codearith(fs, OP_UNM, e, &e2);
705705 break;
src/lcode.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.h,v 1.48 2006/03/21 19:28:03 roberto Exp $
2+** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
src/ldblib.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp $
2+** $Id: ldblib.c,v 1.104.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Interface from Lua to its debug API
44 ** See Copyright Notice in lua.h
55 */
src/ldebug.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.c,v 2.29a 2005/12/22 16:19:56 roberto Exp $
2+** $Id: ldebug.c,v 2.29.1.3 2007/12/28 15:32:23 roberto Exp $
33 ** Debug Interface
44 ** See Copyright Notice in lua.h
55 */
@@ -563,8 +563,8 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { · 557 unmodified lines
563563
564564
565565 void luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
566− if (ttisstring(p1)) p1 = p2;
567− lua_assert(!ttisstring(p1));
566+ if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
567+ lua_assert(!ttisstring(p1) && !ttisnumber(p1));
568568 luaG_typeerror(L, p1, "concatenate");
569569 }
570570
src/ldebug.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.h,v 2.3 2005/04/25 19:24:10 roberto Exp $
2+** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Auxiliary functions from Debug Interface module
44 ** See Copyright Notice in lua.h
55 */
src/ldo.c+12−10
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.c,v 2.38 2006/06/05 19:36:14 roberto Exp $
2+** $Id: ldo.c,v 2.38.1.2 2008/01/03 15:20:39 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -83,7 +83,7 @@ static void resetstack (lua_State *L, int status) { · 77 unmodified lines
8383 L->base = L->ci->base;
8484 luaF_close(L, L->base); /* close eventual pending closures */
8585 luaD_seterrorobj(L, status, L->base);
86− L->nCcalls = 0;
86+ L->nCcalls = L->baseCcalls;
8787 L->allowhook = 1;
8888 restore_stack_limit(L);
8989 L->errfunc = 0;
@@ -417,22 +417,24 @@ static int resume_error (lua_State *L, const char *msg) { · 327 unmodified lines
417417 LUA_API int lua_resume (lua_State *L, int nargs) {
418418 int status;
419419 lua_lock(L);
420− if (L->status != LUA_YIELD) {
421− if (L->status != 0)
422− return resume_error(L, "cannot resume dead coroutine");
423− else if (L->ci != L->base_ci)
420+ if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci))
424421 return resume_error(L, "cannot resume non-suspended coroutine");
425− }
422+ if (L->nCcalls >= LUAI_MAXCCALLS)
423+ return resume_error(L, "C stack overflow");
426424 luai_userstateresume(L, nargs);
427− lua_assert(L->errfunc == 0 && L->nCcalls == 0);
425+ lua_assert(L->errfunc == 0);
426+ L->baseCcalls = ++L->nCcalls;
428427 status = luaD_rawrunprotected(L, resume, L->top - nargs);
429428 if (status != 0) { /* error? */
430429 L->status = cast_byte(status); /* mark thread as `dead' */
431430 luaD_seterrorobj(L, status, L->top);
432431 L->ci->top = L->top;
433432 }
434− else
433+ else {
434+ lua_assert(L->nCcalls == L->baseCcalls);
435435 status = L->status;
436+ }
437+ --L->nCcalls;
436438 lua_unlock(L);
437439 return status;
438440 }
@@ -441,7 +443,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 2 unmodified lines
441443 LUA_API int lua_yield (lua_State *L, int nresults) {
442444 luai_userstateyield(L, nresults);
443445 lua_lock(L);
444− if (L->nCcalls > 0)
446+ if (L->nCcalls > L->baseCcalls)
445447 luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
446448 L->base = L->top - nresults; /* protect stack slots below */
447449 L->status = LUA_YIELD;
src/ldo.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.h,v 2.7 2005/08/24 16:15:49 roberto Exp $
2+** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
src/ldump.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldump.c,v 1.15 2006/02/16 15:53:49 lhf Exp $
2+** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** save precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
src/lfunc.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lfunc.c,v 2.12a 2005/12/22 16:19:56 roberto Exp $
2+** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $
33 ** Auxiliary functions to manipulate prototypes and closures
44 ** See Copyright Notice in lua.h
55 */
src/lfunc.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lfunc.h,v 2.4 2005/04/25 19:24:10 roberto Exp $
2+** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Auxiliary functions to manipulate prototypes and closures
44 ** See Copyright Notice in lua.h
55 */
src/lgc.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.c,v 2.38 2006/05/24 14:34:06 roberto Exp $
2+** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
src/lgc.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.h,v 2.15 2005/08/24 16:15:49 roberto Exp $
2+** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
src/linit.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: linit.c,v 1.14 2005/12/29 15:32:11 roberto Exp $
2+** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Initialization of libraries for lua.c
44 ** See Copyright Notice in lua.h
55 */
src/liolib.c+7−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: liolib.c,v 2.73 2006/05/08 20:14:16 roberto Exp $
2+** $Id: liolib.c,v 2.73.1.2 2008/01/02 13:56:00 roberto Exp $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
@@ -106,8 +106,11 @@ static int io_pclose (lua_State *L) { · 100 unmodified lines
106106
107107 static int io_fclose (lua_State *L) {
108108 FILE **p = topfile(L);
109− int ok = (fclose(*p) == 0);
110− *p = NULL;
109+ int ok = 0;
110+ if (*p != stdin && *p != stdout && *p != stderr) {
111+ ok = (fclose(*p) == 0);
112+ *p = NULL;
113+ }
111114 return pushresult(L, ok, NULL);
112115 }
113116
@@ -129,8 +132,7 @@ static int io_close (lua_State *L) { · 15 unmodified lines
129132
130133 static int io_gc (lua_State *L) {
131134 FILE *f = *topfile(L);
132− /* ignore closed files and standard files */
133− if (f != NULL && f != stdin && f != stdout && f != stderr)
135+ if (f != NULL) /* ignore closed files */
134136 aux_close(L);
135137 return 0;
136138 }
src/llex.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.c,v 2.20 2006/03/09 18:14:31 roberto Exp $
2+** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
src/llex.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.h,v 1.58 2006/03/23 18:23:32 roberto Exp $
2+** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
src/llimits.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llimits.h,v 1.69 2005/12/27 17:12:00 roberto Exp $
2+** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Limits, basic types, and some other `installation-dependent' definitions
44 ** See Copyright Notice in lua.h
55 */
src/lmathlib.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmathlib.c,v 1.67 2005/08/26 17:36:32 roberto Exp $
2+** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Standard mathematical library
44 ** See Copyright Notice in lua.h
55 */
src/lmem.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmem.c,v 1.70 2005/12/26 13:35:47 roberto Exp $
2+** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Interface to Memory Manager
44 ** See Copyright Notice in lua.h
55 */
src/lmem.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmem.h,v 1.31 2005/04/25 19:24:10 roberto Exp $
2+** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Interface to Memory Manager
44 ** See Copyright Notice in lua.h
55 */
src/loadlib.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loadlib.c,v 1.54a 2006/07/03 20:16:49 roberto Exp $
2+** $Id: loadlib.c,v 1.52.1.2 2007/12/28 14:58:43 roberto Exp $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
55 **
src/lobject.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.c,v 2.22 2006/02/10 17:43:52 roberto Exp $
2+** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Some generic functions over Lua objects
44 ** See Copyright Notice in lua.h
55 */
src/lobject.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.h,v 2.20 2006/01/18 11:37:34 roberto Exp $
2+** $Id: lobject.h,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Type definitions for Lua objects
44 ** See Copyright Notice in lua.h
55 */
src/lopcodes.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.c,v 1.37 2005/11/08 19:45:36 roberto Exp $
2+** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** See Copyright Notice in lua.h
44 */
55
src/lopcodes.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.h,v 1.125 2006/03/14 19:04:44 roberto Exp $
2+** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Opcodes for Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
src/loslib.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp $
2+** $Id: loslib.c,v 1.19.1.2 2007/12/28 14:58:43 roberto Exp $
33 ** Standard Operating System library
44 ** See Copyright Notice in lua.h
55 */
src/lparser.c+3−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.42a 2006/06/05 15:57:59 roberto Exp $
2+** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -938,6 +938,8 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { · 932 unmodified lines
938938 primaryexp(ls, &nv.v);
939939 if (nv.v.k == VLOCAL)
940940 check_conflict(ls, lh, &nv.v);
941+ luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
942+ "variables in assignment");
941943 assignment(ls, &nv, nvars+1);
942944 }
943945 else { /* assignment -> `=' explist1 */
src/lparser.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.h,v 1.57 2006/03/09 18:14:31 roberto Exp $
2+** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
src/lstate.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.c,v 2.36 2006/05/24 14:15:50 roberto Exp $
2+** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -93,7 +93,7 @@ static void preinit_state (lua_State *L, global_State *g) { · 87 unmodified lines
9393 resethookcount(L);
9494 L->openupval = NULL;
9595 L->size_ci = 0;
96− L->nCcalls = 0;
96+ L->nCcalls = L->baseCcalls = 0;
9797 L->status = 0;
9898 L->base_ci = L->ci = NULL;
9999 L->savedpc = NULL;
@@ -205,7 +205,7 @@ LUA_API void lua_close (lua_State *L) { · 105 unmodified lines
205205 do { /* repeat until no more errors */
206206 L->ci = L->base_ci;
207207 L->base = L->top = L->ci->base;
208− L->nCcalls = 0;
208+ L->nCcalls = L->baseCcalls = 0;
209209 } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
210210 lua_assert(G(L)->tmudata == NULL);
211211 luai_userstateclose(L);
src/lstate.h+2−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.h,v 2.24 2006/02/06 18:27:59 roberto Exp $
2+** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -112,6 +112,7 @@ struct lua_State { · 106 unmodified lines
112112 int stacksize;
113113 int size_ci; /* size of array `base_ci' */
114114 unsigned short nCcalls; /* number of nested C calls */
115+ unsigned short baseCcalls; /* nested C calls when resuming coroutine */
115116 lu_byte hookmask;
116117 lu_byte allowhook;
117118 int basehookcount;
src/lstring.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp $
2+** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** String table (keeps all strings handled by Lua)
44 ** See Copyright Notice in lua.h
55 */
src/lstring.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstring.h,v 1.43 2005/04/25 19:24:10 roberto Exp $
2+** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** String table (keep all strings handled by Lua)
44 ** See Copyright Notice in lua.h
55 */
src/lstrlib.c+5−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.132a 2006/04/26 20:41:19 roberto Exp $
2+** $Id: lstrlib.c,v 1.132.1.3 2007/12/28 15:32:23 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -629,10 +629,6 @@ static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, · 623 unmodified lines
629629 lua_gettable(L, 3);
630630 break;
631631 }
632− default: {
633− luaL_argerror(L, 3, "string/function/table expected");
634− return;
635− }
636632 }
637633 if (!lua_toboolean(L, -1)) { /* nil or false? */
638634 lua_pop(L, 1);
@@ -648,11 +644,15 @@ static int str_gsub (lua_State *L) { · 9 unmodified lines
648644 size_t srcl;
649645 const char *src = luaL_checklstring(L, 1, &srcl);
650646 const char *p = luaL_checkstring(L, 2);
647+ int tr = lua_type(L, 3);
651648 int max_s = luaL_optint(L, 4, srcl+1);
652649 int anchor = (*p == '^') ? (p++, 1) : 0;
653650 int n = 0;
654651 MatchState ms;
655652 luaL_Buffer b;
653+ luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
654+ tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
655+ "string/function/table expected");
656656 luaL_buffinit(L, &b);
657657 ms.L = L;
658658 ms.src_init = src;
src/ltable.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.c,v 2.32 2006/01/18 11:49:02 roberto Exp $
2+** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -84,8 +84,8 @@ static const Node dummynode_ = { · 78 unmodified lines
8484 static Node *hashnum (const Table *t, lua_Number n) {
8585 unsigned int a[numints];
8686 int i;
87− n += 1; /* normalize number (avoid -0) */
88− lua_assert(sizeof(a) <= sizeof(n));
87+ if (luai_numeq(n, 0)) /* avoid problems with -0 */
88+ return gnode(t, 0);
8989 memcpy(a, &n, sizeof(a));
9090 for (i = 1; i < numints; i++) a[0] += a[i];
9191 return hashmod(t, a[0]);
src/ltable.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.h,v 2.10 2006/01/10 13:13:06 roberto Exp $
2+** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
src/ltablib.c+3−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltablib.c,v 1.38 2005/10/23 17:38:15 roberto Exp $
2+** $Id: ltablib.c,v 1.38.1.2 2007/12/28 15:32:23 roberto Exp $
33 ** Library for Table Manipulation
44 ** See Copyright Notice in lua.h
55 */
@@ -118,7 +118,8 @@ static int tinsert (lua_State *L) { · 112 unmodified lines
118118 static int tremove (lua_State *L) {
119119 int e = aux_getn(L, 1);
120120 int pos = luaL_optint(L, 2, e);
121− if (e == 0) return 0; /* table is `empty' */
121+ if (!(1 <= pos && pos <= e)) /* position is outside bounds? */
122+ return 0; /* nothing to remove */
122123 luaL_setn(L, 1, e - 1); /* t.n = n-1 */
123124 lua_rawgeti(L, 1, pos); /* result = t[pos] */
124125 for ( ;pos<e; pos++) {
src/ltm.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltm.c,v 2.8 2006/01/10 12:50:00 roberto Exp $
2+** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Tag methods
44 ** See Copyright Notice in lua.h
55 */
src/ltm.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltm.h,v 2.6 2005/06/06 13:30:25 roberto Exp $
2+** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Tag methods
44 ** See Copyright Notice in lua.h
55 */
src/lua.c+4−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.c,v 1.160 2006/06/02 15:34:00 roberto Exp $
2+** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -74,6 +74,8 @@ static int report (lua_State *L, int status) { · 68 unmodified lines
7474
7575
7676 static int traceback (lua_State *L) {
77+ if (!lua_isstring(L, 1)) /* 'message' not a string? */
78+ return 1; /* keep it intact */
7779 lua_getfield(L, LUA_GLOBALSINDEX, "debug");
7880 if (!lua_istable(L, -1)) {
7981 lua_pop(L, 1);
@@ -144,7 +146,7 @@ static int dostring (lua_State *L, const char *s, const char *name) { · 64 unmodified lines
144146 static int dolibrary (lua_State *L, const char *name) {
145147 lua_getglobal(L, "require");
146148 lua_pushstring(L, name);
147− return report(L, lua_pcall(L, 1, 0, 0));
149+ return report(L, docall(L, 1, 1));
148150 }
149151
150152
src/lua.h+7−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.h,v 1.218a 2006/06/02 15:34:00 roberto Exp $
2+** $Id: lua.h,v 1.218.1.4 2008/01/03 15:41:15 roberto Exp $
33 ** Lua - An Extensible Extension Language
44 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
55 ** See Copyright Notice at the end of this file
@@ -17,9 +17,9 @@ · 11 unmodified lines
1717
1818
1919 #define LUA_VERSION "Lua 5.1"
20−#define LUA_RELEASE "Lua 5.1.2"
20+#define LUA_RELEASE "Lua 5.1.3"
2121 #define LUA_VERSION_NUM 501
22−#define LUA_COPYRIGHT "Copyright (C) 1994-2007 Lua.org, PUC-Rio"
22+#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
2323 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
2424
2525
@@ -294,6 +294,9 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); · 268 unmodified lines
294294 #define lua_Chunkwriter lua_Writer
295295
296296
297+/* hack */
298+LUA_API void lua_setlevel (lua_State *from, lua_State *to);
299+
297300
298301 /*
299302 ** {======================================================================
@@ -359,7 +362,7 @@ struct lua_Debug { · 59 unmodified lines
359362
360363
361364 /******************************************************************************
362−* Copyright (C) 1994-2007 Lua.org, PUC-Rio. All rights reserved.
365+* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved.
363366 *
364367 * Permission is hereby granted, free of charge, to any person obtaining
365368 * a copy of this software and associated documentation files (the
src/luaconf.h+3−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luaconf.h,v 1.82a 2006/04/10 18:27:23 roberto Exp $
2+** $Id: luaconf.h,v 1.82.1.5 2008/01/17 14:04:20 roberto Exp $
33 ** Configuration file for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -442,7 +442,8 @@ · 436 unmodified lines
442442 ** functions. This limit is arbitrary; its only purpose is to stop C
443443 ** functions to consume unlimited stack space.
444444 */
445−#define LUAI_MAXCSTACK 2048
445+#define LUAI_MCS_AUX ((int)(INT_MAX / (4*sizeof(LUA_NUMBER))))
446+#define LUAI_MAXCSTACK (LUAI_MCS_AUX > SHRT_MAX ? SHRT_MAX : LUAI_MCS_AUX)
446447
447448
448449
src/lualib.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lualib.h,v 1.36 2005/12/27 17:12:00 roberto Exp $
2+** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Lua standard libraries
44 ** See Copyright Notice in lua.h
55 */
src/lundump.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lundump.c,v 1.60 2006/02/16 15:53:49 lhf Exp $
2+** $Id: lundump.c,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** load precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
src/lundump.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lundump.h,v 1.40 2005/11/11 14:03:13 lhf Exp $
2+** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** load precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
src/lvm.c+4−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lvm.c,v 2.63a 2006/06/05 15:58:59 roberto Exp $
2+** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -61,11 +61,9 @@ static void traceexec (lua_State *L, const Instruction *pc) { · 55 unmodified lines
6161 lu_byte mask = L->hookmask;
6262 const Instruction *oldpc = L->savedpc;
6363 L->savedpc = pc;
64− if (mask > LUA_MASKLINE) { /* instruction-hook set? */
65− if (L->hookcount == 0) {
66− resethookcount(L);
67− luaD_callhook(L, LUA_HOOKCOUNT, -1);
68− }
64+ if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {
65+ resethookcount(L);
66+ luaD_callhook(L, LUA_HOOKCOUNT, -1);
6967 }
7068 if (mask & LUA_MASKLINE) {
7169 Proto *p = ci_func(L->ci)->l.p;
src/lvm.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lvm.h,v 2.5 2005/08/22 18:54:49 roberto Exp $
2+** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
src/lzio.c+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp $
2+** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** a generic input stream interface
44 ** See Copyright Notice in lua.h
55 */
src/lzio.h+1−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp $
2+** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
33 ** Buffered streams
44 ** See Copyright Notice in lua.h
55 */