Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions deep.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ local deep = {
}

local execQueue = {}
local maxIndex = 1
local minIndex = 1
local execKeys = {}

-- for compatibility with Lua 5.1/5.2
local unpack = rawget(table, "unpack") or unpack
Expand All @@ -44,13 +43,7 @@ deep.queue = function(i, fun, ...)
end

local arg = { ... }

if i < minIndex then
minIndex = i
elseif i > maxIndex then
maxIndex = i
end


if arg and #arg > 0 then
local t = function() return fun(unpack(arg)) end

Expand All @@ -66,18 +59,23 @@ deep.queue = function(i, fun, ...)
table.insert(execQueue[i], fun)
end
end

table.insert(execKeys, i)
end

deep.execute = function()
for i = minIndex, maxIndex do
if execQueue[i] then
for _, fun in pairs(execQueue[i]) do
fun()
if next(execQueue) ~= nil then
table.sort(execKeys)

for k = 1, #execKeys do
for i = 1, #execQueue[execKeys[k]] do
execQueue[execKeys[k]][i]()
end
end

execQueue = {}
execKeys = {}
end

execQueue = {}
end

return deep