MCPcopy Create free account
hub / github.com/DFHack/dfhack / forlimit

Function forlimit

depends/lua/src/lvm.c:135–152  ·  view source on GitHub ↗

** Try to convert a 'for' limit to an integer, preserving the ** semantics of the loop. ** (The following explanation assumes a non-negative step; it is valid ** for negative steps mutatis mutandis.) ** If the limit can be converted to an integer, rounding down, that is ** it. ** Otherwise, check whether the limit can be converted to a number. If ** the number is too large, it is OK to set the li

Source from the content-addressed store, hash-verified

133** case the LUA_MININTEGER limit would still run the loop once.
134*/
135static int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step,
136 int *stopnow) {
137 *stopnow = 0; /* usually, let loops run */
138 if (!luaV_tointeger(obj, p, (step < 0 ? 2 : 1))) { /* not fit in integer? */
139 lua_Number n; /* try to convert to float */
140 if (!tonumber(obj, &n)) /* cannot convert to float? */
141 return 0; /* not a number */
142 if (luai_numlt(0, n)) { /* if true, float is larger than max integer */
143 *p = LUA_MAXINTEGER;
144 if (step < 0) *stopnow = 1;
145 }
146 else { /* float is smaller than min integer */
147 *p = LUA_MININTEGER;
148 if (step >= 0) *stopnow = 1;
149 }
150 }
151 return 1;
152}
153
154
155/*

Callers 1

luaV_executeFunction · 0.85

Calls 1

luaV_tointegerFunction · 0.85

Tested by

no test coverage detected