No way to interrupt a function call?
See original GitHub issueI can’t seem to find a way to interrupt a running function.
Say you have an infinite while loop within a function
function x()
while true do
... code
end
end
And you run that function x (in my case by finding it in the bindings) by calling the call()
method on it. Is there anyway to interrupt it?
I’m running the script in another thread so my UI doesn’t freeze. Usually there is an InterruptedException
thrown whenever the thread gets interrupted with blocking methods but the call method doesn’t seem to throw such exception.
I’m currently just loading a custom library extending from the DebugLib
class with an interrupt field so whenever a new line is processed and the interrupt state is true, the lib will throw a LuaError
. But I wonder if there’s no simpeler solution to this?
Also the above “fix” doesn’t apply to infinite loops since it doesn’t detect infinite loops. You’d have to interrupt the running script which might not always work.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top GitHub Comments
This is a problem I tackled in my project. To solve the run-away while(true) scripts, I created my own class that extends DebugLib, and overrides the onInstruction method. In there, for a given script I keep track of how many instructions are sent through (a simple counter that does +=1).
For my purposes, 1.0e8 was enough of a threshold to throw a ScriptInterruptException, which is a custom exception that extends RuntimeException.
Instead of tracking count of instructions , I solved it by checking whether current thread is interrupted or not.