问题
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