sleep function lua

-- Import the "socket" library to use the sleep function
socket = require("socket")

-- Define a function named "sleep" that takes a parameter "seconds"
function sleep(seconds)
  -- Store the current time in the variable "start"
  local start = socket.gettime()

  -- Repeat until the difference between the current time and "start" is greater than or equal to the specified "seconds"
  repeat
    -- Yield the coroutine, allowing other tasks to execute
    socket.select(nil, nil, 0.01)
  until socket.gettime() - start >= seconds
end

-- Example usage: Sleep for 2 seconds
sleep(2)