我正在尝试创建一个循环计时器功能,该功能将每秒钟发送一个信号一段时间,然后关闭几x
秒钟并重复循环,我对编程完全陌生,所以我不确定该怎么做,我已经阅读几个教程,但我不明白如何编程,我能找到的壁橱是y
z
require 'socket' -- for having a sleep function ( could also use os.execute(sleep 10))
timer = function (time)
local init = os.time()
local diff=os.difftime(os.time(),init)
while diff<time do
coroutine.yield(diff)
diff=os.difftime(os.time(),init)
end
print( 'Timer timed out at '..time..' seconds!')
end
co=coroutine.create(timer)
coroutine.resume(co,30) -- timer starts here!
while coroutine.status(co)~="dead" do
print("time passed",select(2,coroutine.resume(co)))
print('',coroutine.status(co))
socket.sleep(5)
end
但我相信那是一个回调函数,你能帮忙吗,如果可能的话,解释一下程序是如何编写的,抱歉问了这么多,