Comparison

libs/time.lua @ 471:788d4d91ef6b

libs/time: Add monotonic() if lua-system is available
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 Mar 2023 09:51:03 +0000
parent 440:14071b3a46df
comparison
equal deleted inserted replaced
470:e690759c5072 471:788d4d91ef6b
1 -- Import gettime() from LuaSocket, as a way to access high-resolution time 1 -- Import gettime() from LuaSocket, as a way to access high-resolution time
2 -- in a platform-independent way 2 -- in a platform-independent way
3 3
4 local socket_gettime = require "socket".gettime; 4 local socket_gettime = require "socket".gettime;
5 5
6 local monotonic;
7
8 local have_system_lib, system = pcall(require, "system");
9 if have_system_lib then
10 monotonic = system.monotime;
11 end
12
6 return { 13 return {
7 now = socket_gettime; 14 now = socket_gettime;
15 monotonic = monotonic;
8 } 16 }