diff options
| -rw-r--r-- | lobject.h | 4 | ||||
| -rw-r--r-- | lvm.c | 17 |
2 files changed, 13 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.106 2001/06/15 20:36:57 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.107 2001/06/26 13:20:45 roberto Exp roberto $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -55,6 +55,8 @@ typedef struct lua_TObject { | |||
| 55 | #define setnvalue(obj,x) \ | 55 | #define setnvalue(obj,x) \ |
| 56 | { TObject *_o=(obj); _o->tt=LUA_TNUMBER; _o->value.n=(x); } | 56 | { TObject *_o=(obj); _o->tt=LUA_TNUMBER; _o->value.n=(x); } |
| 57 | 57 | ||
| 58 | #define chgnvalue(obj,x) ((obj)->value.n=(x)) | ||
| 59 | |||
| 58 | #define setsvalue(obj,x) \ | 60 | #define setsvalue(obj,x) \ |
| 59 | { TObject *_o=(obj); _o->tt=LUA_TSTRING; _o->value.ts=(x); } | 61 | { TObject *_o=(obj); _o->tt=LUA_TSTRING; _o->value.ts=(x); } |
| 60 | 62 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.187 2001/06/20 17:22:46 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.188 2001/06/26 13:20:45 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -39,9 +39,10 @@ static void luaV_checkGC (lua_State *L, StkId top) { | |||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | const TObject *luaV_tonumber (const TObject *obj, TObject *n) { | 41 | const TObject *luaV_tonumber (const TObject *obj, TObject *n) { |
| 42 | lua_Number num; | ||
| 42 | if (ttype(obj) == LUA_TNUMBER) return obj; | 43 | if (ttype(obj) == LUA_TNUMBER) return obj; |
| 43 | if (ttype(obj) == LUA_TSTRING && luaO_str2d(svalue(obj), &nvalue(n))) { | 44 | if (ttype(obj) == LUA_TSTRING && luaO_str2d(svalue(obj), &num)) { |
| 44 | setttype(n, LUA_TNUMBER); | 45 | setnvalue(n, num); |
| 45 | return n; | 46 | return n; |
| 46 | } | 47 | } |
| 47 | else | 48 | else |
| @@ -580,10 +581,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 580 | luaD_error(L, l_s("`for' limit must be a number")); | 581 | luaD_error(L, l_s("`for' limit must be a number")); |
| 581 | if (luaV_tonumber(ra+2, ra+2) == NULL) | 582 | if (luaV_tonumber(ra+2, ra+2) == NULL) |
| 582 | luaD_error(L, l_s("`for' step must be a number")); | 583 | luaD_error(L, l_s("`for' step must be a number")); |
| 583 | nvalue(ra) -= nvalue(ra+2);/* decrement index (to be incremented) */ | 584 | /* decrement index (to be incremented) */ |
| 585 | chgnvalue(ra, nvalue(ra) - nvalue(ra+2)); | ||
| 584 | pc += -GETARG_sBc(i); /* `jump' to loop end (delta is negated here) */ | 586 | pc += -GETARG_sBc(i); /* `jump' to loop end (delta is negated here) */ |
| 585 | /* store in `ra+1' total number of repetitions */ | 587 | /* store in `ra+1' total number of repetitions */ |
| 586 | nvalue(ra+1) = ((nvalue(ra+1)-nvalue(ra))/nvalue(ra+2)); | 588 | chgnvalue(ra+1, (nvalue(ra+1)-nvalue(ra))/nvalue(ra+2)); |
| 587 | /* go through */ | 589 | /* go through */ |
| 588 | } | 590 | } |
| 589 | case OP_FORLOOP: { | 591 | case OP_FORLOOP: { |
| @@ -591,8 +593,9 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
| 591 | ttype(ra+2) == LUA_TNUMBER); | 593 | ttype(ra+2) == LUA_TNUMBER); |
| 592 | if (ttype(ra) != LUA_TNUMBER) | 594 | if (ttype(ra) != LUA_TNUMBER) |
| 593 | luaD_error(L, l_s("`for' index must be a number")); | 595 | luaD_error(L, l_s("`for' index must be a number")); |
| 594 | if (--nvalue(ra+1) >= 0) { | 596 | chgnvalue(ra+1, nvalue(ra+1) - 1); /* decrement counter */ |
| 595 | nvalue(ra) += nvalue(ra+2); /* increment index */ | 597 | if (nvalue(ra+1) >= 0) { |
| 598 | chgnvalue(ra, nvalue(ra) + nvalue(ra+2)); /* increment index */ | ||
| 596 | dojump(pc, i); /* repeat loop */ | 599 | dojump(pc, i); /* repeat loop */ |
| 597 | } | 600 | } |
| 598 | break; | 601 | break; |
