milisecond सटीकता की जरूरत नहीं है, तो आप सिर्फ एक coroutine समाधान है, जो आप अपने मुख्य पाश के अंत में समय-समय पर फिर से शुरू, जैसे, इस तरह के लिए जा सकते हैं:
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
यह LuaSocket में नींद समारोह का उपयोग करता है आप विकल्प Lua-users Wiki
क्या आप मुझे हर मिनट एक समारोह को कॉल करने के लिए सरल तरीके से अलार्म का उपयोग करने का उदाहरण दे सकते हैं? – Goles
क्या आपने कोड देखा था? लालम संग्रह में एक फ़ाइल "test.lua" है। –
हाँ, धन्यवाद, मुझे लगता है कि मुझे अब उदाहरण मिला है। – Goles