[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Yielding from hooks
- From: RLake@...
- Date: Tue, 22 Apr 2003 17:38:37 -0500
> Hmm. Looks like I'll have to nil all library functions that use lua_call
> to prevent their use. A pity, they tend to be the more useful ones :-(.
In the case of table.foreach, you can rewrite it in Lua (at a slight loss
of speed):
function table.foreach(t, fn)
for k, v in pairs(t) do
local rv = fn(k, v)
if rv then return rv end
end
end
The string stuff is harder, but not impossible.
Of course, you are still stuck if the script calls a slow C routine, but
that's life, I guess.
By the way, it looks to me like the hook stuff is designed so that you can
enable hooks in a signal handler. In that case, rather than using a line or
count hook, you could set a one-time alarm to go off after a bit, which
turns on the count hook with a count of one. The count hook handler would
turn the hook off and yield; just before resuming, you would turn the alarm
back on again. (I might be missing a race condition here, but I think that
would work.) That would be faster, because traceexec wouldn't be called
except when the hook was going to be triggered. In that case, if the hook
handler noticed that it could not yield, it could change the count to
something more reasonable (say, 30) and complain bitterly if that happened
too many times.