Advertisement
Thefdjurt

YieldIfNeeded

Apr 26th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.49 KB | None | 0 0
  1. local oev=...
  2. local pe,qe,c=os.pullEventRaw,os.queueEvent,os.clock
  3. local l,t={lastYield=c()}
  4. if oev~=false and oev~=0 then
  5.   function os.pullEventRaw(...)-- Just so you don't yield too much
  6.     local y={pe(...)}
  7.     l.lastYield=c()
  8.     return unpack(y)
  9.   end
  10. end
  11. function yin()--The whole point of the util; Call with `YIN()`
  12.   t=c()
  13.   if t-l.lastYield>=6.5 then
  14.     qe("") pe()
  15.     l.lastYield=t
  16.     return true
  17.   end
  18. end
  19. _G.YIN=setmetatable({},{__index=l,__call=yin,__metatable=false})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement