Sleeping

Jul 1, 2023  │  m. Jul 1, 2023 by Gleb Buzin

Lua doesn’t provide a standard sleep function, but there are several ways to implement one.

Linux:

function sleep(n)
    os.execute("sleep " .. tonumber(n))
end

Windows:

function sleep(n)
    if n > 0 then
        os.execute("ping -n " .. tonumber(n+1) .. " localhost > NUL")
    end
end

With LuaSocket module (luarocks install luasocket):

socket = require("socket")

socket.sleep(0.2)


Next: File IO