Lua Program Delay

允我心安 提交于 2019-12-01 05:09:01

问题


How would I use this to add a delay of 2 minutes to my Lua program, here is the code for the delay, but I dont know how to add the delay.

function sleep(n)
  local t = os.clock()
  while os.clock() - t <= n do
    -- nothing
  end
end

回答1:


The os.clock function returns the number of seconds of CPU time for the program. So the sleep function of yours waits for n seconds, if you need to delay 2 minutes, just call:

sleep(2*60)

Note that there are some better solutions to implement sleep functions other than busy waiting, see Sleep Function for detail.



来源:https://stackoverflow.com/questions/20512038/lua-program-delay

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!