本文介绍了使用Lua创建计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Lua创建一个计时器,这样我可以指定在X秒过去之后要触发的回调函数.
I would like to create a timer using Lua, in a way that I could specify a callback function to be triggered after X seconds have passed.
实现此目标的最佳方法是什么? (我需要从网络服务器下载一些每小时要分析一次或两次的数据)
What would be the best way to achieve this? ( I need to download some data from a webserver that will be parsed once or twice an hour )
干杯.
推荐答案
尝试lalarm
,在这里: http://www.tecgraf.puc-rio.br/~lhf /ftp/lua/
示例(基于src/test.lua):
Example (based on src/test.lua):
-- alarm([secs,[func]])
alarm(1, function() print(2) end); print(1)
输出:
1
2
这篇关于使用Lua创建计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!