| 239 | |
| 240 | |
| 241 | static int os_time (lua_State *L) { |
| 242 | time_t t; |
| 243 | if (lua_isnoneornil(L, 1)) /* called without args? */ |
| 244 | t = time(NULL); /* get current time */ |
| 245 | else { |
| 246 | struct tm ts; |
| 247 | luaL_checktype(L, 1, LUA_TTABLE); |
| 248 | lua_settop(L, 1); /* make sure table is at the top */ |
| 249 | ts.tm_sec = getfield(L, "sec", 0); |
| 250 | ts.tm_min = getfield(L, "min", 0); |
| 251 | ts.tm_hour = getfield(L, "hour", 12); |
| 252 | ts.tm_mday = getfield(L, "day", -1); |
| 253 | ts.tm_mon = getfield(L, "month", -1) - 1; |
| 254 | ts.tm_year = getfield(L, "year", -1) - 1900; |
| 255 | ts.tm_isdst = getboolfield(L, "isdst"); |
| 256 | t = mktime(&ts); |
| 257 | } |
| 258 | if (t == (time_t)(-1)) |
| 259 | lua_pushnil(L); |
| 260 | else |
| 261 | lua_pushnumber(L, (lua_Number)t); |
| 262 | return 1; |
| 263 | } |
| 264 | |
| 265 | |
| 266 | static int os_difftime (lua_State *L) { |
nothing calls this directly
no test coverage detected