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

Function forlimit

third-party/lua-5.4.6/src/lvm.c:178–196  ·  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

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

Callers 1

forprepFunction · 0.70

Calls 2

luaV_tointegerFunction · 0.70
luaG_forerrorFunction · 0.70

Tested by

no test coverage detected