File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,20 @@ static int os_clock (lua_State *L) {
189189}
190190
191191
192+ #include <sys/time.h>
193+ #include "llimits.h"
194+ static int os_monotonic (lua_State * L ) {
195+ struct timespec ts ;
196+ if (clock_gettime (CLOCK_MONOTONIC , & ts ) == 0 ) {
197+ double seconds = ts .tv_sec + ts .tv_nsec / 1e9 ;
198+ lua_pushnumber (L , cast_num (seconds ));
199+ return 1 ;
200+ } else {
201+ exit (1 );
202+ }
203+ }
204+
205+
192206/*
193207** {======================================================
194208** Time/Date operations
@@ -409,6 +423,7 @@ static const luaL_Reg syslib[] = {
409423 {"execute" , os_execute },
410424 {"exit" , os_exit },
411425 {"getenv" , os_getenv },
426+ {"monotonic" , os_monotonic },
412427 {"remove" , os_remove },
413428 {"rename" , os_rename },
414429 {"setlocale" , os_setlocale },
You can’t perform that action at this time.
0 commit comments