]> git.lizzy.rs Git - lua_async.git/blobdiff - init.lua
Merge branch 'master' of https://github.com/EliasFleckenstein03/lua_async
[lua_async.git] / init.lua
index 749bee6c7dca94355c47ef0d1861dd5ff18211e6..8449a0f1e2c6d962298f08031fd29da90d9edbb0 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -1,15 +1,24 @@
-lua_async = {}
+lua_async = {
+       poll_functions = {},
+}
+
+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)
        lua_async.intervals.step(dtime)
 
-       -- pending callbacks phase is done by minetest
+       -- pending callbacks phase is obsolete
 
        -- idle & prepare phase are obsolete
 
-       -- poll phase is obsolete
+       -- poll phase
+       for func in pairs(lua_async.poll_functions) do
+               func()
+       end
 
        -- check phase
        lua_async.immediates.step(dtime)
@@ -17,7 +26,11 @@ function lua_async.step(dtime)
        -- close phase is obsolete
 end
 
-return function(path)
+return function(path, no_socket)
+       if not no_socket then
+               lua_async.socket = require("socket")
+       end
+
        for _, f in ipairs {
                "timeouts",
                "intervals",
@@ -26,7 +39,8 @@ return function(path)
                "async_await",
                "util",
                "limiting",
+               "events",
        } do
-               dofile(path .. f .. ".lua")
+               dofile(path .. "/" .. f .. ".lua")
        end
 end