Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous delay in Lua? (like JavaScript setTimeout)

I need to asynchronously delay execution of a function in Lua by X milliseconds. Can this be done?

Given a simple JavaScript example:

setTimeout(function() {
    alert('Hello world!');
}, 5000);

What's the Lua equivalent? Coroutines look like they may help, but I'm not sure.

like image 690
velo9 Avatar asked Oct 07 '22 22:10

velo9


2 Answers

Lua itself does not include asynchronous event support. If you're embedding Lua in something larger or using it with libraries, they may be able to provide callback support.

like image 135
Amber Avatar answered Oct 10 '22 03:10

Amber


Try my lalarm library. It depends on alarm, which works in seconds, but can be easily changed to use ualarm if you have it.

like image 26
lhf Avatar answered Oct 10 '22 02:10

lhf