mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
24 lines
558 B
Lua
24 lines
558 B
Lua
-- LibKeepUp
|
|
-- Avoid 'too long without yielding'
|
|
|
|
-- Experimental.
|
|
local generator
|
|
if(os.sleep) then -- Oh! We are in OpenComputers
|
|
local computer=require('computer')
|
|
local __last_uptime=computer.uptime()
|
|
generator=function(sec)
|
|
return function()
|
|
local now=computer.uptime()
|
|
if(now-__last_uptime>=sec) then
|
|
os.sleep(0)
|
|
__last_uptime=now
|
|
end
|
|
end
|
|
end
|
|
else -- In Standard Lua
|
|
generator=function()
|
|
return function() end
|
|
end
|
|
end
|
|
|
|
return generator |