Skip to content

Instantly share code, notes, and snippets.

@kengonakajima
Forked from joshthecoder/gettimeofday.lua
Last active August 29, 2015 14:22
Show Gist options
  • Save kengonakajima/c91646edb999d12a1dd2 to your computer and use it in GitHub Desktop.
Save kengonakajima/c91646edb999d12a1dd2 to your computer and use it in GitHub Desktop.
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) + tonumber(t.tv_usec)/1000000.0
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