Skip to content

Instantly share code, notes, and snippets.

@joshthecoder
Created June 27, 2012 06:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save joshthecoder/3001891 to your computer and use it in GitHub Desktop.
Save joshthecoder/3001891 to your computer and use it in GitHub Desktop.
gettimeofday() via LuaJIT + FFI
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