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.
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.
Try my lalarm library. It depends on alarm
, which works in seconds, but can be easily changed to use ualarm
if you have it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With