mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
Merge pull request #211 from infinikiller64/master
allow system to catch too long without yielding
This commit is contained in:
commit
1bb2c76bd5
@ -1,8 +1,13 @@
|
||||
local hookInterval = 100
|
||||
local deadline = math.huge
|
||||
local hitDeadline = false
|
||||
local function checkDeadline()
|
||||
if computer.realTime() > deadline then
|
||||
debug.sethook(coroutine.running(), checkDeadline, "", 1)
|
||||
if not hitDeadline then
|
||||
deadline = deadline + 0.5
|
||||
end
|
||||
hitDeadline = true
|
||||
error("too long without yielding", 0)
|
||||
end
|
||||
end
|
||||
@ -570,6 +575,7 @@ local function main()
|
||||
|
||||
while true do
|
||||
deadline = computer.realTime() + timeout -- timeout global is set by host
|
||||
hitDeadline = false
|
||||
debug.sethook(co, checkDeadline, "", hookInterval)
|
||||
local result = table.pack(coroutine.resume(co, table.unpack(args, 1, args.n)))
|
||||
if not result[1] then
|
||||
@ -584,4 +590,4 @@ end
|
||||
|
||||
-- JNLua converts the coroutine to a string immediately, so we can't get the
|
||||
-- traceback later. Because of that we have to do the error handling here.
|
||||
return pcall(main)
|
||||
return pcall(main)
|
||||
|
Loading…
x
Reference in New Issue
Block a user