Changeset 555
- Timestamp:
- 06/17/08 20:01:11 (4 months ago)
- Files:
-
- trunk/lib/lua51/Makefile.orig (modified) (2 diffs)
- trunk/lib/lua51/lapi.c (modified) (3 diffs)
- trunk/lib/lua51/lapi.h (modified) (1 diff)
- trunk/lib/lua51/lauxlib.c (modified) (5 diffs)
- trunk/lib/lua51/lauxlib.h (modified) (1 diff)
- trunk/lib/lua51/lbaselib.c (modified) (3 diffs)
- trunk/lib/lua51/ldblib.c (modified) (3 diffs)
- trunk/lib/lua51/ldebug.c (modified) (2 diffs)
- trunk/lib/lua51/ldebug.h (modified) (1 diff)
- trunk/lib/lua51/ldo.c (modified) (6 diffs)
- trunk/lib/lua51/ldo.h (modified) (1 diff)
- trunk/lib/lua51/ldump.c (modified) (1 diff)
- trunk/lib/lua51/lfunc.c (modified) (1 diff)
- trunk/lib/lua51/lfunc.h (modified) (1 diff)
- trunk/lib/lua51/lgc.c (modified) (1 diff)
- trunk/lib/lua51/lgc.h (modified) (1 diff)
- trunk/lib/lua51/linit.c (modified) (1 diff)
- trunk/lib/lua51/liolib.c (modified) (12 diffs)
- trunk/lib/lua51/llex.c (modified) (1 diff)
- trunk/lib/lua51/llex.h (modified) (1 diff)
- trunk/lib/lua51/llimits.h (modified) (1 diff)
- trunk/lib/lua51/lmathlib.c (modified) (1 diff)
- trunk/lib/lua51/lmem.c (modified) (1 diff)
- trunk/lib/lua51/lmem.h (modified) (1 diff)
- trunk/lib/lua51/loadlib.c (modified) (1 diff)
- trunk/lib/lua51/lobject.c (modified) (1 diff)
- trunk/lib/lua51/lobject.h (modified) (1 diff)
- trunk/lib/lua51/lopcodes.c (modified) (1 diff)
- trunk/lib/lua51/lopcodes.h (modified) (1 diff)
- trunk/lib/lua51/loslib.c (modified) (2 diffs)
- trunk/lib/lua51/lparser.c (modified) (1 diff)
- trunk/lib/lua51/lparser.h (modified) (2 diffs)
- trunk/lib/lua51/lstate.c (modified) (3 diffs)
- trunk/lib/lua51/lstate.h (modified) (2 diffs)
- trunk/lib/lua51/lstring.c (modified) (1 diff)
- trunk/lib/lua51/lstring.h (modified) (1 diff)
- trunk/lib/lua51/lstrlib.c (modified) (4 diffs)
- trunk/lib/lua51/ltable.c (modified) (2 diffs)
- trunk/lib/lua51/ltable.h (modified) (1 diff)
- trunk/lib/lua51/ltablib.c (modified) (2 diffs)
- trunk/lib/lua51/ltm.c (modified) (1 diff)
- trunk/lib/lua51/ltm.h (modified) (1 diff)
- trunk/lib/lua51/lua.c (modified) (3 diffs)
- trunk/lib/lua51/lua.h (modified) (4 diffs)
- trunk/lib/lua51/luaconf.h (modified) (3 diffs)
- trunk/lib/lua51/lualib.h (modified) (1 diff)
- trunk/lib/lua51/lundump.c (modified) (4 diffs)
- trunk/lib/lua51/lundump.h (modified) (1 diff)
- trunk/lib/lua51/lvm.c (modified) (2 diffs)
- trunk/lib/lua51/lvm.h (modified) (1 diff)
- trunk/lib/lua51/lzio.c (modified) (1 diff)
- trunk/lib/lua51/lzio.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/lua51/Makefile.orig
r531 r555 100 100 101 101 macosx: 102 $(MAKE) all MYCFLAGS=-DLUA_USE_ MACOSX103 # use this on Mac OS X 10. 4104 # $(MAKE) all MYCFLAGS= "-DLUA_USE_MACOSX -DLUA_USE_READLINE" MYLIBS="-lreadline"102 $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline" 103 # use this on Mac OS X 10.3- 104 # $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX 105 105 106 106 mingw: … … 149 149 lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ 150 150 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 153 152 lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \ 154 153 ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h trunk/lib/lua51/lapi.c
r270 r555 1 1 /* 2 ** $Id: lapi.c,v 2.55 2006/06/07 12:37:17roberto Exp $2 ** $Id: lapi.c,v 2.55.1.3 2008/01/03 15:20:39 roberto Exp $ 3 3 ** Lua API 4 4 ** See Copyright Notice in lua.h … … 124 124 125 125 126 LUA_API void lua_setlevel (lua_State *from, lua_State *to) { 127 to->nCcalls = from->nCcalls; 128 } 129 130 126 131 LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { 127 132 lua_CFunction old; … … 750 755 break; 751 756 } 752 luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));757 if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); 753 758 L->top--; 754 759 lua_unlock(L); trunk/lib/lua51/lapi.h
r269 r555 1 1 /* 2 ** $Id: lapi.h,v 2.2 2005/04/25 19:24:10roberto Exp $2 ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Auxiliary functions from Lua API 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lauxlib.c
r270 r555 1 1 /* 2 ** $Id: lauxlib.c,v 1.159 2006/03/21 19:31:09roberto Exp $2 ** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $ 3 3 ** Auxiliary functions for building Lua libraries 4 4 ** See Copyright Notice in lua.h … … 245 245 int size = libsize(l); 246 246 /* check whether lib already exists */ 247 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size);247 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); 248 248 lua_getfield(L, -1, libname); /* get _LOADED[libname] */ 249 249 if (!lua_istable(L, -1)) { /* not found? */ … … 536 536 } 537 537 if (feof(lf->f)) return NULL; 538 *size = fread(lf->buff, 1, LUAL_BUFFERSIZE, lf->f);538 *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); 539 539 return (*size > 0) ? lf->buff : NULL; 540 540 } … … 571 571 if (c == '\n') c = getc(lf.f); 572 572 } 573 if (c == LUA_SIGNATURE[0] && lf.f != stdin) { /* binary file? */ 574 fclose(lf.f); 575 lf.f = fopen(filename, "rb"); /* reopen in binary mode */ 573 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ 574 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ 576 575 if (lf.f == NULL) return errfile(L, "reopen", fnameindex); 577 576 /* skip eventual `#!...' */ … … 582 581 status = lua_load(L, getF, &lf, lua_tostring(L, -1)); 583 582 readstatus = ferror(lf.f); 584 if ( lf.f != stdin) fclose(lf.f); /* close file (even in case of errors) */583 if (filename) fclose(lf.f); /* close file (even in case of errors) */ 585 584 if (readstatus) { 586 585 lua_settop(L, fnameindex); /* ignore results from `lua_load' */ trunk/lib/lua51/lauxlib.h
r270 r555 1 1 /* 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 $ 3 3 ** Auxiliary functions for building Lua libraries 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lbaselib.c
r531 r555 1 1 /* 2 ** $Id: lbaselib.c,v 1.191 a 2006/06/02 15:34:00roberto Exp $2 ** $Id: lbaselib.c,v 1.191.1.4 2008/01/20 13:53:22 roberto Exp $ 3 3 ** Basic library 4 4 ** See Copyright Notice in lua.h … … 478 478 */ 479 479 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 480 516 static int auxresume (lua_State *L, lua_State *co, int narg) { 481 int status ;517 int status = costatus(L, co); 482 518 if (!lua_checkstack(co, narg)) 483 519 luaL_error(L, "too many arguments to resume"); 484 if ( lua_status(co) == 0 && lua_gettop(co) == 0) {485 lua_push literal(L, "cannot resume dead coroutine");520 if (status != CO_SUS) { 521 lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); 486 522 return -1; /* error flag */ 487 523 } 488 524 lua_xmove(L, co, narg); 525 lua_setlevel(L, co); 489 526 status = lua_resume(co, narg); 490 527 if (status == 0 || status == LUA_YIELD) { … … 557 594 558 595 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 else575 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 587 596 static int luaB_corunning (lua_State *L) { 588 597 if (lua_pushthread(L)) 589 return 0; /* main thread is not a coroutine */ 590 else 591 return 1; 598 lua_pushnil(L); /* main thread is not a coroutine */ 599 return 1; 592 600 } 593 601 trunk/lib/lua51/ldblib.c
r269 r555 1 1 /* 2 ** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp $2 ** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $ 3 3 ** Interface from Lua to its debug API 4 4 ** See Copyright Notice in lua.h … … 256 256 257 257 static int db_sethook (lua_State *L) { 258 int arg; 258 int arg, mask, count; 259 lua_Hook func; 259 260 lua_State *L1 = getthread(L, &arg); 260 261 if (lua_isnoneornil(L, arg+1)) { 261 262 lua_settop(L, arg+1); 262 lua_sethook(L1, NULL, 0, 0); /* turn off hooks */263 func = NULL; mask = 0; count = 0; /* turn off hooks */ 263 264 } 264 265 else { 265 266 const char *smask = luaL_checkstring(L, arg+2); 266 int count = luaL_optint(L, arg+3, 0);267 267 luaL_checktype(L, arg+1, LUA_TFUNCTION); 268 lua_sethook(L1, hookf, makemask(smask, count), count); 269 } 270 gethooktable(L1); 271 lua_pushlightuserdata(L1, L1); 268 count = luaL_optint(L, arg+3, 0); 269 func = hookf; mask = makemask(smask, count); 270 } 271 gethooktable(L); 272 lua_pushlightuserdata(L, L1); 272 273 lua_pushvalue(L, arg+1); 273 lua_ xmove(L, L1, 1);274 lua_ rawset(L1, -3); /* set new hook*/275 lua_ pop(L1, 1); /* remove hook table*/274 lua_rawset(L, -3); /* set new hook */ 275 lua_pop(L, 1); /* remove hook table */ 276 lua_sethook(L1, func, mask, count); /* set hooks */ 276 277 return 0; 277 278 } … … 287 288 lua_pushliteral(L, "external hook"); 288 289 else { 289 gethooktable(L1); 290 lua_pushlightuserdata(L1, L1); 291 lua_rawget(L1, -2); /* get hook */ 292 lua_remove(L1, -2); /* remove hook table */ 293 lua_xmove(L1, L, 1); 290 gethooktable(L); 291 lua_pushlightuserdata(L, L1); 292 lua_rawget(L, -2); /* get hook */ 293 lua_remove(L, -2); /* remove hook table */ 294 294 } 295 295 lua_pushstring(L, unmakemask(mask, buff)); trunk/lib/lua51/ldebug.c
r533 r555 1 1 /* 2 ** $Id: ldebug.c,v 2.29 a 2005/12/22 16:19:56roberto Exp $2 ** $Id: ldebug.c,v 2.29.1.3 2007/12/28 15:32:23 roberto Exp $ 3 3 ** Debug Interface 4 4 ** See Copyright Notice in lua.h … … 563 563 564 564 void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { 565 if (ttisstring(p1) ) p1 = p2;566 lua_assert(!ttisstring(p1) );565 if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; 566 lua_assert(!ttisstring(p1) && !ttisnumber(p1)); 567 567 luaG_typeerror(L, p1, "concatenate"); 568 568 } trunk/lib/lua51/ldebug.h
r269 r555 1 1 /* 2 ** $Id: ldebug.h,v 2.3 2005/04/25 19:24:10roberto Exp $2 ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Auxiliary functions from Debug Interface module 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/ldo.c
r270 r555 1 1 /* 2 ** $Id: ldo.c,v 2.38 2006/06/05 19:36:14roberto Exp $2 ** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ 3 3 ** Stack and Call structure of Lua 4 4 ** See Copyright Notice in lua.h … … 84 84 luaF_close(L, L->base); /* close eventual pending closures */ 85 85 luaD_seterrorobj(L, status, L->base); 86 L->nCcalls = 0;86 L->nCcalls = L->baseCcalls; 87 87 L->allowhook = 1; 88 88 restore_stack_limit(L); … … 333 333 luaD_callhook(L, LUA_HOOKRET, -1); 334 334 if (f_isLua(L->ci)) { /* Lua function? */ 335 while ( L->ci->tailcalls--) /* call hook for eventualtail calls */335 while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ 336 336 luaD_callhook(L, LUA_HOOKTAILRET, -1); 337 337 } … … 418 418 int status; 419 419 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)) 424 421 return resume_error(L, "cannot resume non-suspended coroutine"); 425 } 422 if (L->nCcalls >= LUAI_MAXCCALLS) 423 return resume_error(L, "C stack overflow"); 426 424 luai_userstateresume(L, nargs); 427 lua_assert(L->errfunc == 0 && L->nCcalls == 0); 425 lua_assert(L->errfunc == 0); 426 L->baseCcalls = ++L->nCcalls; 428 427 status = luaD_rawrunprotected(L, resume, L->top - nargs); 429 428 if (status != 0) { /* error? */ … … 432 431 L->ci->top = L->top; 433 432 } 434 else 433 else { 434 lua_assert(L->nCcalls == L->baseCcalls); 435 435 status = L->status; 436 } 437 --L->nCcalls; 436 438 lua_unlock(L); 437 439 return status; … … 442 444 luai_userstateyield(L, nresults); 443 445 lua_lock(L); 444 if (L->nCcalls > 0)446 if (L->nCcalls > L->baseCcalls) 445 447 luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); 446 448 L->base = L->top - nresults; /* protect stack slots below */ trunk/lib/lua51/ldo.h
r269 r555 1 1 /* 2 ** $Id: ldo.h,v 2.7 2005/08/24 16:15:49roberto Exp $2 ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Stack and Call structure of Lua 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/ldump.c
r269 r555 1 1 /* 2 ** $Id: ldump.c,v 1.15 2006/02/16 15:53:49 lhfExp $2 ** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** save precompiled Lua chunks 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lfunc.c
r531 r555 1 1 /* 2 ** $Id: lfunc.c,v 2.12 a 2005/12/22 16:19:56roberto Exp $2 ** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ 3 3 ** Auxiliary functions to manipulate prototypes and closures 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lfunc.h
r269 r555 1 1 /* 2 ** $Id: lfunc.h,v 2.4 2005/04/25 19:24:10roberto Exp $2 ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Auxiliary functions to manipulate prototypes and closures 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lgc.c
r270 r555 1 1 /* 2 ** $Id: lgc.c,v 2.38 2006/05/24 14:34:06roberto Exp $2 ** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Garbage Collector 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lgc.h
r269 r555 1 1 /* 2 ** $Id: lgc.h,v 2.15 2005/08/24 16:15:49roberto Exp $2 ** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Garbage Collector 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/linit.c
r532 r555 1 1 /* 2 ** $Id: linit.c,v 1.14 2005/12/29 15:32:11roberto Exp $2 ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Initialization of libraries for lua.c 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/liolib.c
r270 r555 1 1 /* 2 ** $Id: liolib.c,v 2.73 2006/05/08 20:14:16roberto Exp $2 ** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $ 3 3 ** Standard I/O (and system) library 4 4 ** See Copyright Notice in lua.h … … 52 52 53 53 54 #define to pfile(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))54 #define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) 55 55 56 56 … … 71 71 72 72 static FILE *tofile (lua_State *L) { 73 FILE **f = to pfile(L);73 FILE **f = tofilep(L); 74 74 if (*f == NULL) 75 75 luaL_error(L, "attempt to use a closed file"); … … 94 94 95 95 /* 96 ** this function has a separated environment, which defines the 97 ** correct __close for 'popen' files 96 ** function to (not) close the standard files stdin, stdout, and stderr 97 */ 98 static int io_noclose (lua_State *L) { 99 lua_pushnil(L); 100 lua_pushliteral(L, "cannot close standard file"); 101 return 2; 102 } 103 104 105 /* 106 ** function to close 'popen' files 98 107 */ 99 108 static int io_pclose (lua_State *L) { 100 FILE **p = to pfile(L);109 FILE **p = tofilep(L); 101 110 int ok = lua_pclose(L, *p); 102 111 *p = NULL; … … 105 114 106 115 116 /* 117 ** function to close regular files 118 */ 107 119 static int io_fclose (lua_State *L) { 108 FILE **p = to pfile(L);120 FILE **p = tofilep(L); 109 121 int ok = (fclose(*p) == 0); 110 122 *p = NULL; … … 129 141 130 142 static int io_gc (lua_State *L) { 131 FILE *f = *to pfile(L);132 /* ignore closed files and standard files*/133 if (f != NULL && f != stdin && f != stdout && f != stderr)143 FILE *f = *tofilep(L); 144 /* ignore closed files */ 145 if (f != NULL) 134 146 aux_close(L); 135 147 return 0; … … 138 150 139 151 static int io_tostring (lua_State *L) { 140 FILE *f = *to pfile(L);152 FILE *f = *tofilep(L); 141 153 if (f == NULL) 142 lua_push string(L, "file (closed)");154 lua_pushliteral(L, "file (closed)"); 143 155 else 144 156 lua_pushfstring(L, "file (%p)", f); … … 156 168 157 169 170 /* 171 ** this function has a separated environment, which defines the 172 ** correct __close for 'popen' files 173 */ 158 174 static int io_popen (lua_State *L) { 159 175 const char *filename = luaL_checkstring(L, 1); … … 281 297 if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ 282 298 luaL_pushresult(&b); /* close buffer */ 283 return (lua_ strlen(L, -1) > 0); /* check whether read something */299 return (lua_objlen(L, -1) > 0); /* check whether read something */ 284 300 } 285 301 l = strlen(p); … … 309 325 } while (n > 0 && nr == rlen); /* until end of count or eof */ 310 326 luaL_pushresult(&b); /* close buffer */ 311 return (n == 0 || lua_ strlen(L, -1) > 0);327 return (n == 0 || lua_objlen(L, -1) > 0); 312 328 } 313 329 … … 503 519 lua_rawseti(L, LUA_ENVIRONINDEX, k); 504 520 } 505 lua_setfield(L, -2, fname); 521 lua_pushvalue(L, -2); /* copy environment */ 522 lua_setfenv(L, -2); /* set it */ 523 lua_setfield(L, -3, fname); 524 } 525 526 527 static void newfenv (lua_State *L, lua_CFunction cls) { 528 lua_createtable(L, 0, 1); 529 lua_pushcfunction(L, cls); 530 lua_setfield(L, -2, "__close"); 506 531 } 507 532 … … 510 535 createmeta(L); 511 536 /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ 512 lua_createtable(L, 2, 1);537 newfenv(L, io_fclose); 513 538 lua_replace(L, LUA_ENVIRONINDEX); 514 539 /* open library */ 515 540 luaL_register(L, LUA_IOLIBNAME, iolib); 516 541 /* create (and set) default files */ 542 newfenv(L, io_noclose); /* close function for default files */ 517 543 createstdfile(L, stdin, IO_INPUT, "stdin"); 518 544 createstdfile(L, stdout, IO_OUTPUT, "stdout"); 519 545 createstdfile(L, stderr, 0, "stderr"); 520 /* create environment for 'popen'*/546 lua_pop(L, 1); /* pop environment for default files */ 521 547 lua_getfield(L, -1, "popen"); 522 lua_createtable(L, 0, 1); 523 lua_pushcfunction(L, io_pclose); 524 lua_setfield(L, -2, "__close"); 525 lua_setfenv(L, -2); 548 newfenv(L, io_pclose); /* create environment for 'popen' */ 549 lua_setfenv(L, -2); /* set fenv for 'popen' */ 526 550 lua_pop(L, 1); /* pop 'popen' */ 527 /* set default close function */528 lua_pushcfunction(L, io_fclose);529 lua_setfield(L, LUA_ENVIRONINDEX, "__close");530 551 return 1; 531 552 } trunk/lib/lua51/llex.c
r533 r555 1 1 /* 2 ** $Id: llex.c,v 2.20 2006/03/09 18:14:31roberto Exp $2 ** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Lexical Analyzer 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/llex.h
r533 r555 1 1 /* 2 ** $Id: llex.h,v 1.58 2006/03/23 18:23:32roberto Exp $2 ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Lexical Analyzer 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/llimits.h
r269 r555 1 1 /* 2 ** $Id: llimits.h,v 1.69 2005/12/27 17:12:00roberto Exp $2 ** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Limits, basic types, and some other `installation-dependent' definitions 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lmathlib.c
r532 r555 1 1 /* 2 ** $Id: lmathlib.c,v 1.67 2005/08/26 17:36:32roberto Exp $2 ** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Standard mathematical library 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lmem.c
r269 r555 1 1 /* 2 ** $Id: lmem.c,v 1.70 2005/12/26 13:35:47roberto Exp $2 ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Interface to Memory Manager 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lmem.h
r269 r555 1 1 /* 2 ** $Id: lmem.h,v 1.31 2005/04/25 19:24:10roberto Exp $2 ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Interface to Memory Manager 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/loadlib.c
r531 r555 1 1 /* 2 ** $Id: loadlib.c,v 1.5 4a 2006/07/03 20:16:49roberto Exp $2 ** $Id: loadlib.c,v 1.52.1.2 2007/12/28 14:58:43 roberto Exp $ 3 3 ** Dynamic library loader for Lua 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lobject.c
r269 r555 1 1 /* 2 ** $Id: lobject.c,v 2.22 2006/02/10 17:43:52roberto Exp $2 ** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Some generic functions over Lua objects 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lobject.h
r269 r555 1 1 /* 2 ** $Id: lobject.h,v 2.20 2006/01/18 11:37:34roberto Exp $2 ** $Id: lobject.h,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Type definitions for Lua objects 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lopcodes.c
r269 r555 1 1 /* 2 ** $Id: lopcodes.c,v 1.37 2005/11/08 19:45:36roberto Exp $2 ** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** See Copyright Notice in lua.h 4 4 */ trunk/lib/lua51/lopcodes.h
r270 r555 1 1 /* 2 ** $Id: lopcodes.h,v 1.125 2006/03/14 19:04:44roberto Exp $2 ** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Opcodes for Lua virtual machine 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/loslib.c
r532 r555 1 1 /* 2 ** $Id: loslib.c,v 1. 20 2006/09/19 13:57:08 roberto Exp $2 ** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $ 3 3 ** Standard Operating System library 4 4 ** See Copyright Notice in lua.h … … 218 218 static int os_exit (lua_State *L) { 219 219 exit(luaL_optint(L, 1, EXIT_SUCCESS)); 220 return 0; /* to avoid warnings */221 220 } 222 221 trunk/lib/lua51/lparser.c
r533 r555 1 1 /* 2 ** $Id: lparser.c,v 2.42 a 2006/06/05 15:57:59roberto Exp $2 ** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ 3 3 ** Lua Parser 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lparser.h
r533 r555 1 1 /* 2 ** $Id: lparser.h,v 1.57 2006/03/09 18:14:31roberto Exp $2 ** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Lua Parser 4 4 ** See Copyright Notice in lua.h … … 13 13 14 14 15 /*16 ** Expression descriptor17 */18 15 19 16 LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, trunk/lib/lua51/lstate.c
r270 r555 1 1 /* 2 ** $Id: lstate.c,v 2.36 2006/05/24 14:15:50roberto Exp $2 ** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ 3 3 ** Global State 4 4 ** See Copyright Notice in lua.h … … 94 94 L->openupval = NULL; 95 95 L->size_ci = 0; 96 L->nCcalls = 0;96 L->nCcalls = L->baseCcalls = 0; 97 97 L->status = 0; 98 98 L->base_ci = L->ci = NULL; … … 206 206 L->ci = L->base_ci; 207 207 L->base = L->top = L->ci->base; 208 L->nCcalls = 0;208 L->nCcalls = L->baseCcalls = 0; 209 209 } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); 210 210 lua_assert(G(L)->tmudata == NULL); trunk/lib/lua51/lstate.h
r269 r555 1 1 /* 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 $ 3 3 ** Global State 4 4 ** See Copyright Notice in lua.h … … 113 113 int size_ci; /* size of array `base_ci' */ 114 114 unsigned short nCcalls; /* number of nested C calls */ 115 unsigned short baseCcalls; /* nested C calls when resuming coroutine */ 115 116 lu_byte hookmask; 116 117 lu_byte allowhook; trunk/lib/lua51/lstring.c
r269 r555 1 1 /* 2 ** $Id: lstring.c,v 2.8 2005/12/22 16:19:56roberto Exp $2 ** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** String table (keeps all strings handled by Lua) 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lstring.h
r269 r555 1 1 /* 2 ** $Id: lstring.h,v 1.43 2005/04/25 19:24:10roberto Exp $2 ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** String table (keep all strings handled by Lua) 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lstrlib.c
r532 r555 1 1 /* 2 ** $Id: lstrlib.c,v 1.132 a 2006/04/26 20:41:19roberto Exp $2 ** $Id: lstrlib.c,v 1.132.1.3 2007/12/28 15:32:23 roberto Exp $ 3 3 ** Standard library for string operations and pattern-matching 4 4 ** See Copyright Notice in lua.h … … 630 630 break; 631 631 } 632 default: {633 luaL_argerror(L, 3, "string/function/table expected");634 return;635 }636 632 } 637 633 if (!lua_toboolean(L, -1)) { /* nil or false? */ … … 649 645 const char *src = luaL_checklstring(L, 1, &srcl); 650 646 const char *p = luaL_checkstring(L, 2); 647 int tr = lua_type(L, 3); 651 648 int max_s = luaL_optint(L, 4, srcl+1); 652 649 int anchor = (*p == '^') ? (p++, 1) : 0; … … 654 651 MatchState ms; 655 652 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"); 656 656 luaL_buffinit(L, &b); 657 657 ms.L = L; trunk/lib/lua51/ltable.c
r269 r555 1 1 /* 2 ** $Id: ltable.c,v 2.32 2006/01/18 11:49:02roberto Exp $2 ** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $ 3 3 ** Lua tables (hash) 4 4 ** See Copyright Notice in lua.h … … 85 85 unsigned int a[numints]; 86 86 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); 89 89 memcpy(a, &n, sizeof(a)); 90 90 for (i = 1; i < numints; i++) a[0] += a[i]; trunk/lib/lua51/ltable.h
r269 r555 1 1 /* 2 ** $Id: ltable.h,v 2.10 2006/01/10 13:13:06roberto Exp $2 ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Lua tables (hash) 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/ltablib.c
r269 r555 1 1 /* 2 ** $Id: ltablib.c,v 1.38 2005/10/23 17:38:15roberto Exp $2 ** $Id: ltablib.c,v 1.38.1.2 2007/12/28 15:32:23 roberto Exp $ 3 3 ** Library for Table Manipulation 4 4 ** See Copyright Notice in lua.h … … 119 119 int e = aux_getn(L, 1); 120 120 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 */ 122 123 luaL_setn(L, 1, e - 1); /* t.n = n-1 */ 123 124 lua_rawgeti(L, 1, pos); /* result = t[pos] */ trunk/lib/lua51/ltm.c
r269 r555 1 1 /* 2 ** $Id: ltm.c,v 2.8 2006/01/10 12:50:00roberto Exp $2 ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 3 ** Tag methods 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/ltm.h
r269 r555 1 1 /* 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 $ 3 3 ** Tag methods 4 4 ** See Copyright Notice in lua.h trunk/lib/lua51/lua.c
r270 r555 1 1 /* 2 ** $Id: lua.c,v 1.160 2006/06/02 15:34:00roberto Exp $2 ** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $ 3 3 ** Lua stand-alone interpreter 4 4 ** See Copyright Notice in lua.h … … 75 75 76 76 static int traceback (lua_State *L) { 77 if (!lua_isstring(L, 1)) /* 'message' not a string? */ 78 return 1; /* keep it intact */ 77 79 lua_getfield(L, LUA_GLOBALSINDEX, "debug"); 78 80 if (!lua_istable(L, -1)) { … … 145 147 lua_getglobal(L, "require"); 146 148 <
