** Try to convert a 'for' limit to an integer, preserving the semantics ** of the loop. Return true if the loop must not run; otherwise, '*p' ** gets the integer limit. ** (The following explanation assumes a positive step; it is valid for ** negative steps mutatis mutandis.) ** If the limit is an integer or can be converted to an integer, ** rounding down, that is the limit. ** Otherwise, check w
| 186 | ** an initial value equal to LUA_MININTEGER.) |
| 187 | */ |
| 188 | static int forlimit (lua_State *L, lua_Integer init, const TValue *lim, |
| 189 | lua_Integer *p, lua_Integer step) { |
| 190 | if (!luaV_tointeger(lim, p, (step < 0 ? F2Iceil : F2Ifloor))) { |
| 191 | /* not coercible to in integer */ |
| 192 | lua_Number flim; /* try to convert to float */ |
| 193 | if (!tonumber(lim, &flim)) /* cannot convert to float? */ |
| 194 | luaG_forerror(L, lim, "limit"); |
| 195 | /* else 'flim' is a float out of integer bounds */ |
| 196 | if (luai_numlt(0, flim)) { /* if it is positive, it is too large */ |
| 197 | if (step < 0) return 1; /* initial value must be less than it */ |
| 198 | *p = LUA_MAXINTEGER; /* truncate */ |
| 199 | } |
| 200 | else { /* it is less than min integer */ |
| 201 | if (step > 0) return 1; /* initial value must be greater than it */ |
| 202 | *p = LUA_MININTEGER; /* truncate */ |
| 203 | } |
| 204 | } |
| 205 | return (step > 0 ? init > *p : init < *p); /* not to run? */ |
| 206 | } |
| 207 | |
| 208 | |
| 209 | /* |
no test coverage detected