From 4734c179f7e82a5b72fc251d164555825127c293 Mon Sep 17 00:00:00 2001 From: PixelToast Date: Tue, 15 Apr 2014 19:08:15 -0400 Subject: [PATCH 1/2] allow system to catch too long without yielding gives system 0.5 seconds to yield before crashing. makes it much much less annoying, and its still safe: while true do end -> error while true do pcall(function() while true do end end) end -> system crash --- src/main/resources/assets/opencomputers/lua/kernel.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/resources/assets/opencomputers/lua/kernel.lua b/src/main/resources/assets/opencomputers/lua/kernel.lua index 384ccc5c0..cd3a9aa1b 100644 --- a/src/main/resources/assets/opencomputers/lua/kernel.lua +++ b/src/main/resources/assets/opencomputers/lua/kernel.lua @@ -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) \ No newline at end of file +return pcall(main) From f49066ee2002ec94712c0808e8c755b5255616f6 Mon Sep 17 00:00:00 2001 From: PixelToast Date: Tue, 15 Apr 2014 19:12:53 -0400 Subject: [PATCH 2/2] stupid github editor is stupid --- src/main/resources/assets/opencomputers/lua/kernel.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/assets/opencomputers/lua/kernel.lua b/src/main/resources/assets/opencomputers/lua/kernel.lua index cd3a9aa1b..ef8945ac4 100644 --- a/src/main/resources/assets/opencomputers/lua/kernel.lua +++ b/src/main/resources/assets/opencomputers/lua/kernel.lua @@ -6,7 +6,7 @@ local function checkDeadline() debug.sethook(coroutine.running(), checkDeadline, "", 1) if not hitDeadline then deadline = deadline + 0.5 - end + end hitDeadline = true error("too long without yielding", 0) end