Created
June 27, 2012 06:18
gettimeofday() via LuaJIT + FFI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ffi = require("ffi") | |
ffi.cdef[[ | |
typedef long time_t; | |
typedef struct timeval { | |
time_t tv_sec; | |
time_t tv_usec; | |
} timeval; | |
int gettimeofday(struct timeval* t, void* tzp); | |
]] | |
local function gettimeofday() | |
local t = ffi.new("timeval") | |
ffi.C.gettimeofday(t, nil) | |
return tonumber(t.tv_sec) | |
end | |
print("time of day is " .. gettimeofday()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment