require 'alien'
local timespec = alien.defstruct {
{ 'sec', 'long' },
{ 'nsec', 'long' },
}
local CLOCK_REALTIME = 0
local CLOCK_SECOND = 13
local def = alien.default
def.clock_gettime:types('int', 'int', 'pointer')
function clock_gettime(clock)
local tp = timespec:new()
def.clock_gettime(clock, tp())
return tp.sec, tp.nsec
end
-- here starts the program
sec, nsec = clock_gettime(CLOCK_REALTIME)
print('CLOCK_REALTIME = ' .. sec .. '.' .. string.format('%09d', nsec))
sec, nsec = clock_gettime(CLOCK_SECOND)
print('CLOCK_SECOND = ' .. sec .. '.' .. string.format('%09d', nsec))