lua-users home
lua-l archive

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


On 15 August 2011 15:25, Igor Medeiros <igorosbergster@gmail.com> wrote:
> There is a library that provides a sleep function in milliseconds? I tried
> using the posix.sleep() function but it only wait seconds instead
> miliseconds.

You could use `socket.sleep(time)` from the luasocket library [1]. The
parameter `time` is in seconds, but it has millisecond precision, i.e.
to sleep 1 millisecond, call:

socket.sleep(0.001)

It works also on Windows, but it uses the Sleep function from Windows
API [2], which is not precise down to 1 millisecond (AFAIK the minimum
it sleeps is ~15ms [3]).

[1] http://w3.impa.br/~diego/software/luasocket/socket.html#sleep
[2] http://msdn.microsoft.com/en-us/library/ms686298.aspx
[3] http://social.msdn.microsoft.com/Forums/en/clr/thread/facc2b57-9a27-4049-bb32-ef093fbf4c29