Showing the changes to src (8 of 15 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lbaselib.c,v 1.191 2006/06/02 15:34:00 roberto Exp $ | |
| 2 | +** $Id: lbaselib.c,v 1.191a 2006/06/02 15:34:00 roberto Exp $ | |
| 3 | 3 | ** Basic library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State *L) { · 108 unmodified lines | ||
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
| 117 | −static void getfunc (lua_State *L) { | |
| 117 | +static void getfunc (lua_State *L, int opt) { | |
| 118 | 118 | if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); |
| 119 | 119 | else { |
| 120 | 120 | lua_Debug ar; |
| 121 | − int level = luaL_optint(L, 1, 1); | |
| 121 | + int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); | |
| 122 | 122 | luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); |
| 123 | 123 | if (lua_getstack(L, level, &ar) == 0) |
| 124 | 124 | luaL_argerror(L, 1, "invalid level"); |
| @@ -131,7 +131,7 @@ static void getfunc (lua_State *L) { · 6 unmodified lines | ||
| 131 | 131 | |
| 132 | 132 | |
| 133 | 133 | static int luaB_getfenv (lua_State *L) { |
| 134 | − getfunc(L); | |
| 134 | + getfunc(L, 1); | |
| 135 | 135 | if (lua_iscfunction(L, -1)) /* is a C function? */ |
| 136 | 136 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ |
| 137 | 137 | else |
| @@ -142,7 +142,7 @@ static int luaB_getfenv (lua_State *L) { · 4 unmodified lines | ||
| 142 | 142 | |
| 143 | 143 | static int luaB_setfenv (lua_State *L) { |
| 144 | 144 | luaL_checktype(L, 2, LUA_TTABLE); |
| 145 | − getfunc(L); | |
| 145 | + getfunc(L, 0); | |
| 146 | 146 | lua_pushvalue(L, 2); |
| 147 | 147 | if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { |
| 148 | 148 | /* change environment of current thread */ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp $ | |
| 2 | +** $Id: lcode.c,v 2.25a 2006/03/21 19:28:49 roberto Exp $ | |
| 3 | 3 | ** Code generator for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -35,15 +35,20 @@ static int isnumeral(expdesc *e) { · 29 unmodified lines | ||
| 35 | 35 | void luaK_nil (FuncState *fs, int from, int n) { |
| 36 | 36 | Instruction *previous; |
| 37 | 37 | if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ |
| 38 | − if (fs->pc == 0) /* function start? */ | |
| 39 | − return; /* positions are already clean */ | |
| 40 | − if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) { | |
| 41 | − int pfrom = GETARG_A(*previous); | |
| 42 | − int pto = GETARG_B(*previous); | |
| 43 | − if (pfrom <= from && from <= pto+1) { /* can connect both? */ | |
| 44 | − if (from+n-1 > pto) | |
| 45 | − SETARG_B(*previous, from+n-1); | |
| 46 | − return; | |
| 38 | + if (fs->pc == 0) { /* function start? */ | |
| 39 | + if (from >= fs->nactvar) | |
| 40 | + return; /* positions are already clean */ | |
| 41 | + } | |
| 42 | + else { | |
| 43 | + previous = &fs->f->code[fs->pc-1]; | |
| 44 | + if (GET_OPCODE(*previous) == OP_LOADNIL) { | |
| 45 | + int pfrom = GETARG_A(*previous); | |
| 46 | + int pto = GETARG_B(*previous); | |
| 47 | + if (pfrom <= from && from <= pto+1) { /* can connect both? */ | |
| 48 | + if (from+n-1 > pto) | |
| 49 | + SETARG_B(*previous, from+n-1); | |
| 50 | + return; | |
| 51 | + } | |
| 47 | 52 | } |
| 48 | 53 | } |
| 49 | 54 | } |
| @@ -657,10 +662,16 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { · 607 unmodified lines | ||
| 657 | 662 | if (constfolding(op, e1, e2)) |
| 658 | 663 | return; |
| 659 | 664 | else { |
| 660 | − int o1 = luaK_exp2RK(fs, e1); | |
| 661 | 665 | int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; |
| 662 | − freeexp(fs, e2); | |
| 663 | − freeexp(fs, e1); | |
| 666 | + int o1 = luaK_exp2RK(fs, e1); | |
| 667 | + if (o1 > o2) { | |
| 668 | + freeexp(fs, e1); | |
| 669 | + freeexp(fs, e2); | |
| 670 | + } | |
| 671 | + else { | |
| 672 | + freeexp(fs, e2); | |
| 673 | + freeexp(fs, e1); | |
| 674 | + } | |
| 664 | 675 | e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); |
| 665 | 676 | e1->k = VRELOCABLE; |
| 666 | 677 | } |
| @@ -718,10 +729,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { · 51 unmodified lines | ||
| 718 | 729 | luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ |
| 719 | 730 | break; |
| 720 | 731 | } |
| 721 | − default: { | |
| 732 | + case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: | |
| 733 | + case OPR_MOD: case OPR_POW: { | |
| 722 | 734 | if (!isnumeral(v)) luaK_exp2RK(fs, v); |
| 723 | 735 | break; |
| 724 | 736 | } |
| 737 | + default: { | |
| 738 | + luaK_exp2RK(fs, v); | |
| 739 | + break; | |
| 740 | + } | |
| 725 | 741 | } |
| 726 | 742 | } |
| 727 | 743 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $ | |
| 2 | +** $Id: ldebug.c,v 2.29a 2005/12/22 16:19:56 roberto Exp $ | |
| 3 | 3 | ** Debug Interface |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -432,14 +432,16 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { · 426 unmodified lines | ||
| 432 | 432 | break; |
| 433 | 433 | } |
| 434 | 434 | case OP_CLOSURE: { |
| 435 | − int nup; | |
| 435 | + int nup, j; | |
| 436 | 436 | check(b < pt->sizep); |
| 437 | 437 | nup = pt->p[b]->nups; |
| 438 | 438 | check(pc + nup < pt->sizecode); |
| 439 | − for (; nup>0; nup--) { | |
| 440 | − OpCode op1 = GET_OPCODE(pt->code[pc+nup]); | |
| 439 | + for (j = 1; j <= nup; j++) { | |
| 440 | + OpCode op1 = GET_OPCODE(pt->code[pc + j]); | |
| 441 | 441 | check(op1 == OP_GETUPVAL || op1 == OP_MOVE); |
| 442 | 442 | } |
| 443 | + if (reg != NO_REG) /* tracing? */ | |
| 444 | + pc += nup; /* do not 'execute' these pseudo-instructions */ | |
| 443 | 445 | break; |
| 444 | 446 | } |
| 445 | 447 | case OP_VARARG: { |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp $ | |
| 2 | +** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp $ | |
| 3 | 3 | ** Standard Operating System library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -146,11 +146,22 @@ static int os_date (lua_State *L) { · 140 unmodified lines | ||
| 146 | 146 | setboolfield(L, "isdst", stm->tm_isdst); |
| 147 | 147 | } |
| 148 | 148 | else { |
| 149 | − char b[256]; | |
| 150 | − if (strftime(b, sizeof(b), s, stm)) | |
| 151 | − lua_pushstring(L, b); | |
| 152 | − else | |
| 153 | − return luaL_error(L, LUA_QL("date") " format too long"); | |
| 149 | + char cc[3]; | |
| 150 | + luaL_Buffer b; | |
| 151 | + cc[0] = '%'; cc[2] = '\0'; | |
| 152 | + luaL_buffinit(L, &b); | |
| 153 | + for (; *s; s++) { | |
| 154 | + if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ | |
| 155 | + luaL_addchar(&b, *s); | |
| 156 | + else { | |
| 157 | + size_t reslen; | |
| 158 | + char buff[200]; /* should be big enough for any conversion result */ | |
| 159 | + cc[1] = *(++s); | |
| 160 | + reslen = strftime(buff, sizeof(buff), cc, stm); | |
| 161 | + luaL_addlstring(&b, buff, reslen); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + luaL_pushresult(&b); | |
| 154 | 165 | } |
| 155 | 166 | return 1; |
| 156 | 167 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lparser.c,v 2.42 2006/06/05 15:57:59 roberto Exp $ | |
| 2 | +** $Id: lparser.c,v 2.42a 2006/06/05 15:57:59 roberto Exp $ | |
| 3 | 3 | ** Lua Parser |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -489,7 +489,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) { · 483 unmodified lines | ||
| 489 | 489 | |
| 490 | 490 | static void listfield (LexState *ls, struct ConsControl *cc) { |
| 491 | 491 | expr(ls, &cc->v); |
| 492 | − luaY_checklimit(ls->fs, cc->na, MAXARG_Bx, "items in a constructor"); | |
| 492 | + luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); | |
| 493 | 493 | cc->na++; |
| 494 | 494 | cc->tostore++; |
| 495 | 495 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstrlib.c,v 1.132 2006/04/26 20:41:19 roberto Exp $ | |
| 2 | +** $Id: lstrlib.c,v 1.132a 2006/04/26 20:41:19 roberto Exp $ | |
| 3 | 3 | ** Standard library for string operations and pattern-matching |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { · 717 unmodified lines | ||
| 723 | 723 | |
| 724 | 724 | static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { |
| 725 | 725 | const char *p = strfrmt; |
| 726 | − while (strchr(FLAGS, *p)) p++; /* skip flags */ | |
| 726 | + while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ | |
| 727 | 727 | if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) |
| 728 | 728 | luaL_error(L, "invalid format (repeated flags)"); |
| 729 | 729 | if (isdigit(uchar(*p))) p++; /* skip width */ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lua.h,v 1.218 2006/06/02 15:34:00 roberto Exp $ | |
| 2 | +** $Id: lua.h,v 1.218a 2006/06/02 15:34:00 roberto Exp $ | |
| 3 | 3 | ** Lua - An Extensible Extension Language |
| 4 | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
| 5 | 5 | ** See Copyright Notice at the end of this file |
| @@ -17,9 +17,9 @@ · 11 unmodified lines | ||
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | #define LUA_VERSION "Lua 5.1" |
| 20 | −#define LUA_RELEASE "Lua 5.1.1" | |
| 20 | +#define LUA_RELEASE "Lua 5.1.2" | |
| 21 | 21 | #define LUA_VERSION_NUM 501 |
| 22 | −#define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio" | |
| 22 | +#define LUA_COPYRIGHT "Copyright (C) 1994-2007 Lua.org, PUC-Rio" | |
| 23 | 23 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" |
| 24 | 24 | |
| 25 | 25 | |
| @@ -359,7 +359,7 @@ struct lua_Debug { · 333 unmodified lines | ||
| 359 | 359 | |
| 360 | 360 | |
| 361 | 361 | /****************************************************************************** |
| 362 | −* Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved. | |
| 362 | +* Copyright (C) 1994-2007 Lua.org, PUC-Rio. All rights reserved. | |
| 363 | 363 | * |
| 364 | 364 | * Permission is hereby granted, free of charge, to any person obtaining |
| 365 | 365 | * a copy of this software and associated documentation files (the |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: print.c,v 1.55 2006/05/31 13:30:05 lhf Exp $ | |
| 2 | +** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $ | |
| 3 | 3 | ** print bytecodes |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -32,6 +32,7 @@ static void PrintString(const TString* ts) · 26 unmodified lines | ||
| 32 | 32 | switch (c) |
| 33 | 33 | { |
| 34 | 34 | case '"': printf("\\\""); break; |
| 35 | + case '\\': printf("\\\\"); break; | |
| 35 | 36 | case '\a': printf("\\a"); break; |
| 36 | 37 | case '\b': printf("\\b"); break; |
| 37 | 38 | case '\f': printf("\\f"); break; |