lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Get time of day.
@function gettimeofday
@see gettimeofday(2)
@return time in seconds
@return remainder in nanoseconds
static int Pgettimeofday(lua_State *L)
struct timeval tv;
if (gettimeofday(&tv, NULL) == -1)
return pusherror(L, "gettimeofday");

lua_pushstring(L, "sec");
lua_pushinteger(L, tv.tv_sec);
lua_settable(L, -3);
lua_pushstring(L, "usec");
lua_pushinteger(L, tv.tv_usec);
lua_settable(L, -3);
return 1;

struct timeval {

    time_t      tv_sec;     /* seconds */
    suseconds_t tv_usec;    /* microseconds */

According to the implement of this function and the definition of struct timeval,
It does return a table with 'sec' and 'usec' fields, and field 'usec' really represents microseconds.
So I think The documents is wrong.

2013/6/5 Rena <>
I'm a bit confused by
It seems to suggest that posix.gettimeofday() should return two values, but instead it returns a table with 'sec' and 'usec' fields. Further, it claims the second value should be nanoseconds, while suggests it should be microseconds (which seems to be consistent with the values I'm getting). Is this documentation up to date?

Sent from my Game Boy.