Merge pull request #211 from infinikiller64/master

allow system to catch too long without yielding
This commit is contained in:
Florian Nücke 2014-04-17 16:42:21 +02:00
commit 1bb2c76bd5

View File

@ -1,8 +1,13 @@
local hookInterval = 100 local hookInterval = 100
local deadline = math.huge local deadline = math.huge
local hitDeadline = false
local function checkDeadline() local function checkDeadline()
if computer.realTime() > deadline then if computer.realTime() > deadline then
debug.sethook(coroutine.running(), checkDeadline, "", 1) debug.sethook(coroutine.running(), checkDeadline, "", 1)
if not hitDeadline then
deadline = deadline + 0.5
end
hitDeadline = true
error("too long without yielding", 0) error("too long without yielding", 0)
end end
end end
@ -570,6 +575,7 @@ local function main()
while true do while true do
deadline = computer.realTime() + timeout -- timeout global is set by host deadline = computer.realTime() + timeout -- timeout global is set by host
hitDeadline = false
debug.sethook(co, checkDeadline, "", hookInterval) debug.sethook(co, checkDeadline, "", hookInterval)
local result = table.pack(coroutine.resume(co, table.unpack(args, 1, args.n))) local result = table.pack(coroutine.resume(co, table.unpack(args, 1, args.n)))
if not result[1] then if not result[1] then