Skip to content

Instantly share code, notes, and snippets.

@mrwonko
Created July 31, 2012 13:23
Show Gist options
  • Save mrwonko/3217014 to your computer and use it in GitHub Desktop.
Save mrwonko/3217014 to your computer and use it in GitHub Desktop.
a lua hook that's called every 1000 instructions
local function hook(event)
assert(event == "count")
local info = debug.getinfo(2, "Sl") -- get source file related info (S) and current line (l)
error("Code took to long (over 1000 instructions), aborted at file \"" .. info.short_src .. "\" line " .. info.currentline)
end
debug.sethook(hook, "", 1000) -- "" = when to call this hook, if any of "every line", "every function call" or "every function return", 1000 = call every 1000 instructions
local i = 0
while true do
print(i)
i = i + 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment