| 168 | |
| 169 | |
| 170 | static int os_time (lua_State *L) { |
| 171 | time_t t; |
| 172 | if (lua_isnoneornil(L, 1)) /* called without args? */ |
| 173 | t = time(NULL); /* get current time */ |
| 174 | else { |
| 175 | struct tm ts; |
| 176 | luaL_checktype(L, 1, LUA_TTABLE); |
| 177 | lua_settop(L, 1); /* make sure table is at the top */ |
| 178 | ts.tm_sec = getfield(L, "sec", 0); |
| 179 | ts.tm_min = getfield(L, "min", 0); |
| 180 | ts.tm_hour = getfield(L, "hour", 12); |
| 181 | ts.tm_mday = getfield(L, "day", -1); |
| 182 | ts.tm_mon = getfield(L, "month", -1) - 1; |
| 183 | ts.tm_year = getfield(L, "year", -1) - 1900; |
| 184 | ts.tm_isdst = getboolfield(L, "isdst"); |
| 185 | t = mktime(&ts); |
| 186 | } |
| 187 | if (t == (time_t)(-1)) |
| 188 | lua_pushnil(L); |
| 189 | else |
| 190 | lua_pushnumber(L, (lua_Number)t); |
| 191 | return 1; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | static int os_difftime (lua_State *L) { |
nothing calls this directly
no test coverage detected