Software /
code /
verse
Annotate
libs/time.lua @ 503:395ae8df5a9e
squishy: Move bit fallback module out of Prosody namespace
This way, prosody.util.bitcompat should pick it up
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 23 Jun 2023 22:20:24 +0200 |
parent | 471:788d4d91ef6b |
rev | line source |
---|---|
440
14071b3a46df
util.time: Add pure Lua version of Prosody C module
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Import gettime() from LuaSocket, as a way to access high-resolution time |
14071b3a46df
util.time: Add pure Lua version of Prosody C module
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 -- in a platform-independent way |
14071b3a46df
util.time: Add pure Lua version of Prosody C module
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
14071b3a46df
util.time: Add pure Lua version of Prosody C module
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local socket_gettime = require "socket".gettime; |
14071b3a46df
util.time: Add pure Lua version of Prosody C module
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
471
788d4d91ef6b
libs/time: Add monotonic() if lua-system is available
Matthew Wild <mwild1@gmail.com>
parents:
440
diff
changeset
|
6 local monotonic; |
788d4d91ef6b
libs/time: Add monotonic() if lua-system is available
Matthew Wild <mwild1@gmail.com>
parents:
440
diff
changeset
|
7 |
788d4d91ef6b
libs/time: Add monotonic() if lua-system is available
Matthew Wild <mwild1@gmail.com>
parents:
440
diff
changeset
|
8 local have_system_lib, system = pcall(require, "system"); |
788d4d91ef6b
libs/time: Add monotonic() if lua-system is available
Matthew Wild <mwild1@gmail.com>
parents:
440
diff
changeset
|
9 if have_system_lib then |
788d4d91ef6b
libs/time: Add monotonic() if lua-system is available
Matthew Wild <mwild1@gmail.com>
parents:
440
diff
changeset
|
10 monotonic = system.monotime; |
788d4d91ef6b
libs/time: Add monotonic() if lua-system is available
Matthew Wild <mwild1@gmail.com>
parents:
440
diff
changeset
|
11 end |
788d4d91ef6b
libs/time: Add monotonic() if lua-system is available
Matthew Wild <mwild1@gmail.com>
parents:
440
diff
changeset
|
12 |
440
14071b3a46df
util.time: Add pure Lua version of Prosody C module
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 return { |
14071b3a46df
util.time: Add pure Lua version of Prosody C module
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 now = socket_gettime; |
471
788d4d91ef6b
libs/time: Add monotonic() if lua-system is available
Matthew Wild <mwild1@gmail.com>
parents:
440
diff
changeset
|
15 monotonic = monotonic; |
440
14071b3a46df
util.time: Add pure Lua version of Prosody C module
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 } |