how can i stop a lua function block/call mid execution -
is there way stop lua pcall lua function block mid execution? im using multiple threads , cancel function mid-flight.
the simplest way phone call error('my message') abort execution , homecoming nil, 'my message' result of pcall(). if want abort running coroutine (or "main" chunk) "outside", way know without modifying lua vm attach debug hook coroutine or main chunk , phone call error() debug hook:
print(1) local count = 0 debug.sethook(function(event, line) if count > 1 error('done', 2) end count = count + 1 end, "l") print(2) print(3) print("not getting here") you should see this:
1 2 3 script.lua:4: done in case of pcall, see parameter of error() phone call passed error message pcall.
the conditions check can quite elaborate; example, can check hook called particular function number of commands executed before aborting.
lua
No comments:
Post a Comment