| 247 | |
| 248 | |
| 249 | static 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 | |
| 272 | static const char *checkoption (lua_State *L, const char *conv, |
no test coverage detected