MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / getfield

Function getfield

extlibs/lua/src/loslib.c:249–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247
248
249static int getfield (lua_State *L, const char *key, int d, int delta) {
250 int isnum;
251 int t = lua_getfield(L, -1, key); /* get field and its type */
252 lua_Integer res = lua_tointegerx(L, -1, &isnum);
253 if (!isnum) { /* field is not an integer? */
254 if (t != LUA_TNIL) /* some other value? */
255 return luaL_error(L, "field '%s' is not an integer", key);
256 else if (d < 0) /* absent field; no default? */
257 return luaL_error(L, "field '%s' missing in date table", key);
258 res = d;
259 }
260 else {
261 /* unsigned avoids overflow when lua_Integer has 32 bits */
262 if (!(res >= 0 ? (lua_Unsigned)res <= (lua_Unsigned)INT_MAX + delta
263 : (lua_Integer)INT_MIN + delta <= res))
264 return luaL_error(L, "field '%s' is out-of-bound", key);
265 res -= delta;
266 }
267 lua_pop(L, 1);
268 return (int)res;
269}
270
271
272static const char *checkoption (lua_State *L, const char *conv,

Callers 1

os_timeFunction · 0.85

Calls 3

lua_getfieldFunction · 0.85
lua_tointegerxFunction · 0.85
luaL_errorFunction · 0.85

Tested by

no test coverage detected