MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / forlimit

Function forlimit

3rd/lua-5.4.3/src/lvm.c:176–194  ·  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

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

Callers 1

forprepFunction · 0.85

Calls 2

luaV_tointegerFunction · 0.85
luaG_forerrorFunction · 0.85

Tested by

no test coverage detected