MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / os_time

Function os_time

lib/lua/src/loslib.c:346–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344
345
346static 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
372static 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