Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sleep for Windows #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

#vim swap
*.swp
*.sublime-*
28 changes: 28 additions & 0 deletions lib/idle.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--idle.lua

--replace with your own funciton


--[[
--https://github.com/andrewstarks/lsleep
local success, lsleep= pcall(require, 'lsleep')
--]]




local function unix_idle (t)

local ret = os.execute('sleep '..t)
if _VERSION =='Lua 5.1' and ret ~= 0
or _VERSION =='Lua 5.2' or _VERSION == "Lua 5.3" and ret ~= true then
os.exit()
end
end

local function windows_idle (t)
os.execute( ('ping 1.1.1.1 -n 1 -w %d > nul'):format(t * 1000) )
end

return --success and lsleep.sleep or
os.getenv('OS'):match("^Windows-.") and windows_idle or unix_idle
12 changes: 4 additions & 8 deletions sched.lua
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,11 @@ end
-- This function should idle up to t time units. Replace with
-- whatever your app uses. LuaSocket's sleep works just fine.
-- It is allowed to idle for less than t; the empty function will
-- result in a busy wait. Defaults to execution of Linux's "sleep" command.
-- result in a busy wait. Defaults to execution of Linux's "sleep" command
-- or the Windows ping hack.
-- @param t time to idle
M.idle = function (t)
local ret = os.execute('sleep '..t)
if _VERSION =='Lua 5.1' and ret ~= 0
or _VERSION =='Lua 5.2' and ret ~= true then
os.exit()
end
end
M.idle = require 'lumen.lib.idle'


local cycleready = {}

Expand Down