aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-02-14 19:46:43 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-02-14 19:46:43 -0200
commit1e602a61b331a46e3690cc43a6c41074c1de7eab (patch)
tree0303acd3cf8368c8d97ac2710bf6b7adca0bf4e5 /lvm.c
parent57fb51f975c39a063896bccbf4b2e3169f309941 (diff)
downloadlua-1e602a61b331a46e3690cc43a6c41074c1de7eab.tar.gz
lua-1e602a61b331a46e3690cc43a6c41074c1de7eab.tar.bz2
lua-1e602a61b331a46e3690cc43a6c41074c1de7eab.zip
new generic `for'
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/lvm.c b/lvm.c
index cc99b35d..5faae066 100644
--- a/lvm.c
+++ b/lvm.c
@@ -56,7 +56,7 @@ int luaV_tostring (lua_State *L, TObject *obj) {
56 return 0; 56 return 0;
57 else { 57 else {
58 char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ 58 char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */
59 lua_number2str(s, nvalue(obj)); /* convert `s' to number */ 59 lua_number2str(s, nvalue(obj));
60 setsvalue(obj, luaS_new(L, s)); 60 setsvalue(obj, luaS_new(L, s));
61 return 1; 61 return 1;
62 } 62 }
@@ -559,20 +559,23 @@ StkId luaV_execute (lua_State *L) {
559 break; 559 break;
560 } 560 }
561 case OP_TFORLOOP: { 561 case OP_TFORLOOP: {
562 Table *t;
563 int n;
564 int j = GETARG_sBc(i); 562 int j = GETARG_sBc(i);
563 int loop = 0;
565 pc += j; /* jump back before tests (for error messages) */ 564 pc += j; /* jump back before tests (for error messages) */
566 if (ttype(ra) != LUA_TTABLE) 565 if (ttype(ra) == LUA_TTABLE) {
567 luaD_error(L, "`for' table must be a table"); 566 Table *t = hvalue(ra);
568 runtime_check(L, ttype(ra+1) == LUA_TNUMBER); 567 loop = luaH_next(L, t, ra+1);
569 t = hvalue(ra); 568 }
570 n = cast(int, nvalue(ra+1)); 569 else if (ttype(ra) == LUA_TFUNCTION) {
571 n = luaH_nexti(t, n, ra+2); 570 setobj(ra+1, ra);
572 if (n != -1) { /* repeat loop? */ 571 L->top = ra+2; /* no arguments */
573 setnvalue(ra+1, n); /* index */ 572 luaD_call(L, ra+1, 2);
573 L->top = L->ci->top;
574 loop = (ttype(ra+1) != LUA_TNIL);
574 } 575 }
575 else 576 else
577 luaD_error(L, "`for' value must be a table or function");
578 if (!loop)
576 pc -= j; /* undo jump */ 579 pc -= j; /* undo jump */
577 break; 580 break;
578 } 581 }