| 344 | |
| 345 | |
| 346 | static int os_time (lua_State *L) { |
| 347 | time_t t; |
| 348 | if (lua_isnoneornil(L, 1)) /* called without args? */ |
| 349 | t = time(NULL); /* get current time */ |
| 350 | else { |
| 351 | struct tm ts; |
| 352 | luaL_checktype(L, 1, LUA_TTABLE); |
| 353 | lua_settop(L, 1); /* make sure table is at the top */ |
| 354 | ts.tm_year = getfield(L, "year", -1, 1900); |
| 355 | ts.tm_mon = getfield(L, "month", -1, 1); |
| 356 | ts.tm_mday = getfield(L, "day", -1, 0); |
| 357 | ts.tm_hour = getfield(L, "hour", 12, 0); |
| 358 | ts.tm_min = getfield(L, "min", 0, 0); |
| 359 | ts.tm_sec = getfield(L, "sec", 0, 0); |
| 360 | ts.tm_isdst = getboolfield(L, "isdst"); |
| 361 | t = mktime(&ts); |
| 362 | setallfields(L, &ts); /* update fields with normalized values */ |
| 363 | } |
| 364 | if (t != (time_t)(l_timet)t || t == (time_t)(-1)) |
| 365 | return luaL_error(L, |
| 366 | "time result cannot be represented in this installation"); |
| 367 | l_pushtime(L, t); |
| 368 | return 1; |
| 369 | } |
| 370 | |
| 371 | |
| 372 | static int os_difftime (lua_State *L) { |
nothing calls this directly
no test coverage detected