私はループタイマー関数を作成しようとしています。これは、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
しかし、それはコールバック関数のためだったと思います。助けてもらえますか、可能であれば、プログラムがどのように書かれているかを説明してください。多くのことを尋ねてすみません、