diff options
| -rw-r--r-- | lvm.c | 15 |
1 files changed, 8 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.187 2014/03/06 16:15:18 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.188 2014/03/07 16:19:00 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 | */ |
| @@ -899,7 +899,7 @@ void luaV_execute (lua_State *L) { | |||
| 899 | } | 899 | } |
| 900 | ) | 900 | ) |
| 901 | vmcase(OP_FORLOOP, | 901 | vmcase(OP_FORLOOP, |
| 902 | if (ttisinteger(ra)) { /* integer count? */ | 902 | if (ttisinteger(ra)) { /* integer loop? */ |
| 903 | lua_Integer step = ivalue(ra + 2); | 903 | lua_Integer step = ivalue(ra + 2); |
| 904 | lua_Integer idx = ivalue(ra) + step; /* increment index */ | 904 | lua_Integer idx = ivalue(ra) + step; /* increment index */ |
| 905 | lua_Integer limit = ivalue(ra + 1); | 905 | lua_Integer limit = ivalue(ra + 1); |
| @@ -909,7 +909,7 @@ void luaV_execute (lua_State *L) { | |||
| 909 | setivalue(ra + 3, idx); /* ...and external index */ | 909 | setivalue(ra + 3, idx); /* ...and external index */ |
| 910 | } | 910 | } |
| 911 | } | 911 | } |
| 912 | else { /* floating count */ | 912 | else { /* floating loop */ |
| 913 | lua_Number step = fltvalue(ra + 2); | 913 | lua_Number step = fltvalue(ra + 2); |
| 914 | lua_Number idx = luai_numadd(L, fltvalue(ra), step); /* inc. index */ | 914 | lua_Number idx = luai_numadd(L, fltvalue(ra), step); /* inc. index */ |
| 915 | lua_Number limit = fltvalue(ra + 1); | 915 | lua_Number limit = fltvalue(ra + 1); |
| @@ -925,10 +925,11 @@ void luaV_execute (lua_State *L) { | |||
| 925 | TValue *init = ra; | 925 | TValue *init = ra; |
| 926 | TValue *plimit = ra + 1; | 926 | TValue *plimit = ra + 1; |
| 927 | TValue *pstep = ra + 2; | 927 | TValue *pstep = ra + 2; |
| 928 | if (ttisinteger(ra) && ttisinteger(ra + 1) && ttisinteger(ra + 2)) { | 928 | if (ttisinteger(init) && ttisinteger(plimit) && ttisinteger(pstep)) { |
| 929 | setivalue(ra, ivalue(ra) - ivalue(pstep)); | 929 | /* all values are integer */ |
| 930 | setivalue(init, ivalue(init) - ivalue(pstep)); | ||
| 930 | } | 931 | } |
| 931 | else { /* try with floats */ | 932 | else { /* try making all values floats */ |
| 932 | lua_Number ninit; lua_Number nlimit; lua_Number nstep; | 933 | lua_Number ninit; lua_Number nlimit; lua_Number nstep; |
| 933 | if (!tonumber(plimit, &nlimit)) | 934 | if (!tonumber(plimit, &nlimit)) |
| 934 | luaG_runerror(L, LUA_QL("for") " limit must be a number"); | 935 | luaG_runerror(L, LUA_QL("for") " limit must be a number"); |
| @@ -938,7 +939,7 @@ void luaV_execute (lua_State *L) { | |||
| 938 | setnvalue(pstep, nstep); | 939 | setnvalue(pstep, nstep); |
| 939 | if (!tonumber(init, &ninit)) | 940 | if (!tonumber(init, &ninit)) |
| 940 | luaG_runerror(L, LUA_QL("for") " initial value must be a number"); | 941 | luaG_runerror(L, LUA_QL("for") " initial value must be a number"); |
| 941 | setnvalue(ra, luai_numsub(L, ninit, nstep)); | 942 | setnvalue(init, luai_numsub(L, ninit, nstep)); |
| 942 | } | 943 | } |
| 943 | ci->u.l.savedpc += GETARG_sBx(i); | 944 | ci->u.l.savedpc += GETARG_sBx(i); |
| 944 | ) | 945 | ) |
