MCPcopy Create free account
hub / github.com/DFHack/dfhack / os_time

Function os_time

depends/lua/src/loslib.c:325–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323
324
325static 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
351static int os_difftime (lua_State *L) {

Callers

nothing calls this directly

Calls 6

luaL_checktypeFunction · 0.85
lua_settopFunction · 0.85
getfieldFunction · 0.85
getboolfieldFunction · 0.85
setallfieldsFunction · 0.85
luaL_errorFunction · 0.85

Tested by

no test coverage detected