| 323 | |
| 324 | |
| 325 | static int os_time (lua_State *L) { |
| 326 | time_t t; |
| 327 | if (lua_isnoneornil(L, 1)) /* called without args? */ |
| 328 | t = time(NULL); /* get current time */ |
| 329 | else { |
| 330 | struct tm ts; |
| 331 | luaL_checktype(L, 1, LUA_TTABLE); |
| 332 | lua_settop(L, 1); /* make sure table is at the top */ |
| 333 | ts.tm_sec = getfield(L, "sec", 0, 0); |
| 334 | ts.tm_min = getfield(L, "min", 0, 0); |
| 335 | ts.tm_hour = getfield(L, "hour", 12, 0); |
| 336 | ts.tm_mday = getfield(L, "day", -1, 0); |
| 337 | ts.tm_mon = getfield(L, "month", -1, 1); |
| 338 | ts.tm_year = getfield(L, "year", -1, 1900); |
| 339 | ts.tm_isdst = getboolfield(L, "isdst"); |
| 340 | t = mktime(&ts); |
| 341 | setallfields(L, &ts); /* update fields with normalized values */ |
| 342 | } |
| 343 | if (t != (time_t)(l_timet)t || t == (time_t)(-1)) |
| 344 | return luaL_error(L, |
| 345 | "time result cannot be represented in this installation"); |
| 346 | l_pushtime(L, t); |
| 347 | return 1; |
| 348 | } |
| 349 | |
| 350 | |
| 351 | static int os_difftime (lua_State *L) { |
nothing calls this directly
no test coverage detected