diff options
-rw-r--r-- | lvm.c | 13 | ||||
-rw-r--r-- | lvm.h | 5 |
2 files changed, 10 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.216 2002/02/14 21:46:43 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.217 2002/03/04 15:40:04 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 | */ |
@@ -12,7 +12,6 @@ | |||
12 | 12 | ||
13 | #include "lua.h" | 13 | #include "lua.h" |
14 | 14 | ||
15 | #include "lapi.h" | ||
16 | #include "ldebug.h" | 15 | #include "ldebug.h" |
17 | #include "ldo.h" | 16 | #include "ldo.h" |
18 | #include "lfunc.h" | 17 | #include "lfunc.h" |
@@ -542,16 +541,18 @@ StkId luaV_execute (lua_State *L) { | |||
542 | case OP_FORLOOP: { | 541 | case OP_FORLOOP: { |
543 | lua_Number step, index, limit; | 542 | lua_Number step, index, limit; |
544 | int j = GETARG_sBc(i); | 543 | int j = GETARG_sBc(i); |
544 | const TObject *plimit = ra+1; | ||
545 | const TObject *pstep = ra+2; | ||
545 | pc += j; /* jump back before tests (for error messages) */ | 546 | pc += j; /* jump back before tests (for error messages) */ |
546 | if (ttype(ra) != LUA_TNUMBER) | 547 | if (ttype(ra) != LUA_TNUMBER) |
547 | luaD_error(L, "`for' initial value must be a number"); | 548 | luaD_error(L, "`for' initial value must be a number"); |
548 | if (luaV_tonumber(ra+1, ra+1) == NULL) | 549 | if (!tonumber(plimit, ra+1)) |
549 | luaD_error(L, "`for' limit must be a number"); | 550 | luaD_error(L, "`for' limit must be a number"); |
550 | if (luaV_tonumber(ra+2, ra+2) == NULL) | 551 | if (!tonumber(pstep, ra+2)) |
551 | luaD_error(L, "`for' step must be a number"); | 552 | luaD_error(L, "`for' step must be a number"); |
552 | step = nvalue(ra+2); | 553 | step = nvalue(pstep); |
553 | index = nvalue(ra) + step; /* increment index */ | 554 | index = nvalue(ra) + step; /* increment index */ |
554 | limit = nvalue(ra+1); | 555 | limit = nvalue(plimit); |
555 | if (step > 0 ? index <= limit : index >= limit) | 556 | if (step > 0 ? index <= limit : index >= limit) |
556 | chgnvalue(ra, index); /* update index */ | 557 | chgnvalue(ra, index); /* update index */ |
557 | else | 558 | else |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.h,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ | 2 | ** $Id: lvm.h,v 1.36 2002/02/07 17:24:05 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 | */ |
@@ -15,7 +15,8 @@ | |||
15 | 15 | ||
16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) |
17 | 17 | ||
18 | #define tonumber(o,n) (((o) = luaV_tonumber(o,n)) != NULL) | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ |
19 | (((o) = luaV_tonumber(o,n)) != NULL)) | ||
19 | 20 | ||
20 | 21 | ||
21 | const TObject *luaV_tonumber (const TObject *obj, TObject *n); | 22 | const TObject *luaV_tonumber (const TObject *obj, TObject *n); |