[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Timing out LUA programs
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 18 Jun 2002 13:14:14 -0300
>> Is there a safe way to shut down the LUA program after an arbitrary
>> time interval?
>I get the current time when I start the script running (lua_dofile,
>lua_dobuffer, etc.). Then I add a line hook and check the elapsed
>time. If the script runs for too long I call lua_error with an
>appropriate message which interrupts execution of the script.
Having a line hook always active can slow down your program. If your system
has support for timers or alarm you can set up a timer or alarm handler
and in it, when the event happens, set a line or call hook to handle the event.
The lua.c interpreter does something similar to handle interrupts.
A sample implementation of alarm handling can be seen at
It needs signal and SIGALRM. It works with Lua 5.0w0 but with small changes
perhaps also in Lua 4.0.