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

Function getfield

3rd/lua-5.4.3/src/loslib.c:251–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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