MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / forlimit

Function forlimit

third-party/lua-5.5.0/src/lvm.c:181–199  ·  view source on GitHub ↗

** 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

Source from the content-addressed store, hash-verified

179** an initial value equal to LUA_MININTEGER.)
180*/
181static int forlimit (lua_State *L, lua_Integer init, const TValue *lim,
182 lua_Integer *p, lua_Integer step) {
183 if (!luaV_tointeger(lim, p, (step < 0 ? F2Iceil : F2Ifloor))) {
184 /* not coercible to in integer */
185 lua_Number flim; /* try to convert to float */
186 if (!tonumber(lim, &flim)) /* cannot convert to float? */
187 luaG_forerror(L, lim, "limit");
188 /* else 'flim' is a float out of integer bounds */
189 if (luai_numlt(0, flim)) { /* if it is positive, it is too large */
190 if (step < 0) return 1; /* initial value must be less than it */
191 *p = LUA_MAXINTEGER; /* truncate */
192 }
193 else { /* it is less than min integer */
194 if (step > 0) return 1; /* initial value must be greater than it */
195 *p = LUA_MININTEGER; /* truncate */
196 }
197 }
198 return (step > 0 ? init > *p : init < *p); /* not to run? */
199}
200
201
202/*

Callers 1

forprepFunction · 0.70

Calls 2

luaV_tointegerFunction · 0.70
luaG_forerrorFunction · 0.70

Tested by

no test coverage detected