mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
Merge branch 'master-MC1.10' into master-MC1.11
This commit is contained in:
commit
93034c4ca0
@ -41,6 +41,7 @@ if hookInterval < 1000 then hookInterval = 1000 end
|
|||||||
|
|
||||||
local deadline = math.huge
|
local deadline = math.huge
|
||||||
local hitDeadline = false
|
local hitDeadline = false
|
||||||
|
local tooLongWithoutYielding = setmetatable({}, { __tostring = function() return "too long without yielding" end})
|
||||||
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)
|
||||||
@ -48,9 +49,16 @@ local function checkDeadline()
|
|||||||
deadline = deadline + 0.5
|
deadline = deadline + 0.5
|
||||||
end
|
end
|
||||||
hitDeadline = true
|
hitDeadline = true
|
||||||
error("too long without yielding", 0)
|
error(tooLongWithoutYielding)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local function pcallTimeoutCheck(...)
|
||||||
|
local ok, timeout = ...
|
||||||
|
if timeout == tooLongWithoutYielding then
|
||||||
|
return ok, tostring(tooLongWithoutYielding)
|
||||||
|
end
|
||||||
|
return ...
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -739,9 +747,7 @@ sandbox = {
|
|||||||
next = next,
|
next = next,
|
||||||
pairs = pairs,
|
pairs = pairs,
|
||||||
pcall = function(...)
|
pcall = function(...)
|
||||||
local result = table.pack(pcall(...))
|
return pcallTimeoutCheck(pcall(...))
|
||||||
checkDeadline()
|
|
||||||
return table.unpack(result, 1, result.n)
|
|
||||||
end,
|
end,
|
||||||
print = nil, -- in boot/*_base.lua
|
print = nil, -- in boot/*_base.lua
|
||||||
rawequal = rawequal,
|
rawequal = rawequal,
|
||||||
@ -788,15 +794,20 @@ sandbox = {
|
|||||||
_VERSION = _VERSION:match("5.3") and "Lua 5.3" or "Lua 5.2",
|
_VERSION = _VERSION:match("5.3") and "Lua 5.3" or "Lua 5.2",
|
||||||
xpcall = function(f, msgh, ...)
|
xpcall = function(f, msgh, ...)
|
||||||
local handled = false
|
local handled = false
|
||||||
|
checkArg(2, msgh, "function")
|
||||||
local result = table.pack(xpcall(f, function(...)
|
local result = table.pack(xpcall(f, function(...)
|
||||||
if handled then
|
if (...) == tooLongWithoutYielding then
|
||||||
|
return tooLongWithoutYielding
|
||||||
|
elseif handled then
|
||||||
return ...
|
return ...
|
||||||
else
|
else
|
||||||
handled = true
|
handled = true
|
||||||
return msgh(...)
|
return msgh(...)
|
||||||
end
|
end
|
||||||
end, ...))
|
end, ...))
|
||||||
checkDeadline()
|
if result[2] == tooLongWithoutYielding then
|
||||||
|
result = table.pack(result[1], select(2, pcallTimeoutCheck(pcall(msgh, tostring(tooLongWithoutYielding)))))
|
||||||
|
end
|
||||||
return table.unpack(result, 1, result.n)
|
return table.unpack(result, 1, result.n)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -1503,4 +1514,4 @@ end
|
|||||||
|
|
||||||
-- JNLua converts the coroutine to a string immediately, so we can't get the
|
-- 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.
|
-- traceback later. Because of that we have to do the error handling here.
|
||||||
return pcall(main)
|
return pcallTimeoutCheck(pcall(main))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user