diff options
Diffstat (limited to 'lvm.c')
| -rw-r--r-- | lvm.c | 25 |
1 files changed, 14 insertions, 11 deletions
| @@ -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 | } |
