| 237 | #endif |
| 238 | |
| 239 | static int getfield (lua_State *L, const char *key, int d, int delta) { |
| 240 | int isnum; |
| 241 | int t = lua_getfield(L, -1, key); /* get field and its type */ |
| 242 | lua_Integer res = lua_tointegerx(L, -1, &isnum); |
| 243 | if (!isnum) { /* field is not an integer? */ |
| 244 | if (t != LUA_TNIL) /* some other value? */ |
| 245 | return luaL_error(L, "field '%s' is not an integer", key); |
| 246 | else if (d < 0) /* absent field; no default? */ |
| 247 | return luaL_error(L, "field '%s' missing in date table", key); |
| 248 | res = d; |
| 249 | } |
| 250 | else { |
| 251 | if (!(-L_MAXDATEFIELD <= res && res <= L_MAXDATEFIELD)) |
| 252 | return luaL_error(L, "field '%s' is out-of-bound", key); |
| 253 | res -= delta; |
| 254 | } |
| 255 | lua_pop(L, 1); |
| 256 | return (int)res; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | static const char *checkoption (lua_State *L, const char *conv, |
no test coverage detected