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