[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Simple Lua for scripts - Sumary
- From: Rici Lake <lua@...>
- Date: Thu, 25 Aug 2005 18:49:37 -0500
On 25-Aug-05, at 6:12 PM, David Given wrote:
On Thursday 25 August 2005 23:04, Ben Sunshine-Hill wrote:
[...]
Limiting execution time: This is an OS-specific thing. The effect of
it, though, should be to set a line hook in the VM when you decide you
want a script to die suddenly. Then the script will break on the next
line.
Not meaning to contradict you, but:
while true do end
No line hooks!
He might have meant a counthook. You set the counthook to one and it
will trigger on the next VM instruction. Setting the counthook to one
inside of an alarm handler is a standard way of breaking Lua execution
after a certain amount of time.
In any event, in Lua 5.0.2 at least, the above statement does trigger
line hooks. The line hook is triggered by any backwards branch,
regardless of line number:
function hook(what, where)
print ("Hooked!", what, where)
if what == "count" then debug.sethook(hook, "l")
elseif count < 10 then count = count + 1; debug.sethook(hook, "c",
100)
else error("Done!")
end
end
> count = 0
> debug.sethook(hook, "c", 100); while true do end
Hooked! count nil
Hooked! line 1
Hooked! count nil
Hooked! line 1
Hooked! count nil
Hooked! line 1
Hooked! count nil
Hooked! line 1
Hooked! count nil
Hooked! line 1
Hooked! count nil
Hooked! line 1
Hooked! count nil
Hooked! line 1
Hooked! count nil
Hooked! line 1
Hooked! count nil
Hooked! line 1
Hooked! count nil
Hooked! line 1
Hooked! count nil
Hooked! line 1
stdin:5: Done!
stack traceback:
[C]: in function `error'
stdin:5: in function `hook'
stdin:1: in main chunk
[C]: ?