lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


David,

Here's an approach to just this problem I've been considering for other
purposes. Please now that I have not done more than hack around a little
with this idea. It has the advantage of not using a linehook or a timer/
alarm.

The basic idea is to allocate a fixed number of bytecodes the user can
execute. Store a counter somewhere (if you're only using one state it
could be global, otherwise attach it to the lua state struct. Everytime
you execute a bytecode in luaV_execute (in lvm.c) decrement the counter.
When the counter is <= 0 you stop the program. I'm unsure just where the
counter should be checked, probably right in luaV_execute with an error
signaled if the counter runs to zero.

The two problems with this are (1) you can't be sure just how much time a
given number of bytecodes will execute and (2) it requires a fair amount
of messing around with the Lua internals. On the plus side the actual
lines of code you'd need to change are quite small for your application,
on the order of 10.

  - Tom Wrensch

On Tue, 18 Jun 2002, davefowle wrote:

> I am thinking of "embedding" LUA into my program,but I am concerned
> about users writing "never ending" LUA programs.
> 
> Is there a safe way to shut down the LUA program after an arbitrary
> time interval?
> 
> Regards
> 
> David Fowle
> 
> 
>