It feels a little wrong if a newbie like me fixes LHF on Lua issues, but here it goes; passing "count" to debug.sethook is similar to passing "c" or "call", the correct mask to pass the associated function after n VM instructions "".
Thus, to limit the execution time of code loaded from dofile (), use something like the following:
local f = function() error("timeout") end local x,y = xpcall(function() debug.sethook(f, "", 1e8) local ret = dofile("script.lua") debug.sethook() return ret end, debug.traceback)
source share