aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-11-21 16:37:08 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-11-21 16:37:08 +0100
commit40beef755f0c47691b5cd5a79e76fdd361320aa8 (patch)
tree023dc702cab44be6b500dc0f1ef549090498e9b6 /init.lua
parentd8c45339fcef6609dcc423480dcb70986237bf61 (diff)
downloadlua_async-40beef755f0c47691b5cd5a79e76fdd361320aa8.tar.xz
Sleep for unused tick time & optional realtime
- Optional luasocket dependency for realtime measurements (instead of CPU time) - lua_async.run() will wait for the time to be ready
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index 07bea3e..368ffa9 100644
--- a/init.lua
+++ b/init.lua
@@ -1,5 +1,13 @@
lua_async = {}
+if rawget(_G, "require") then
+ lua_async.socket = require("socket")
+end
+
+function lua_async.clock()
+ return lua_async.socket and lua_async.socket.gettime() or os.clock()
+end
+
function lua_async.step(dtime)
-- timers phase
lua_async.timeouts.step(dtime)