Skip to content

Instantly share code, notes, and snippets.

@simcop2387
Created November 29, 2014 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simcop2387/ab73b2a55af466ebe1a9 to your computer and use it in GitHub Desktop.
Save simcop2387/ab73b2a55af466ebe1a9 to your computer and use it in GitHub Desktop.
while 1 do
print("", "badfile")
end
function sandbox(fn)
-- read script and set the environment
f = loadfile(fn, "t")
debug.setupvalue(f, 1, {print = print})
-- create a coroutine and have it yield every 50 instructions
local co = coroutine.create(f)
function mhook()
print("hooked")
print(debug.getinfo(co, 0))
co.yield()
end
debug.sethook(co, mhook, "", 1)
-- demonstrate stepped execution, 5 'ticks'
for i = 1, 50 do
print("tick")
print(coroutine.status(co))
coroutine.resume(co)
end
end
sandbox("badfile.lua")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment