first commit

This commit is contained in:
2021-12-18 20:10:30 +01:00
parent 4d04f63b99
commit 215bed9faf
108 changed files with 3630 additions and 0 deletions

54
lib/knife/convoke.lua Normal file
View File

@@ -0,0 +1,54 @@
return function (routine)
local routines = { routine }
local routineIndex = 1
local isFinished = false
local function execute ()
local continueCount = 0
local run
local function continue ()
continueCount = continueCount + 1
return function (...)
continueCount = continueCount - 1
if continueCount == 0 then
return run(...)
end
end
end
local function wait (...)
return coroutine.yield(...)
end
local r = coroutine.create(function ()
isFinished = false
while routineIndex <= #routines do
routines[routineIndex](continue, wait)
continueCount = 0
routineIndex = routineIndex + 1
end
isFinished = true
end)
run = function (...)
return coroutine.resume(r, ...)
end
run()
end
local function appendOrExecute (routine)
if routine then
routines[#routines + 1] = routine
if isFinished then
execute()
end
return appendOrExecute
else
execute()
end
end
return appendOrExecute
end