Advertisement
fatboychummy

Yieldize

May 31st, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.70 KB | None | 0 0
  1. --[[FATFILE
  2. 2
  3. unknown
  4. does magical bs
  5. Made by Fatboychummy, do not redistribute/edit without permission.
  6. ]]
  7.  
  8.  
  9. local funcs = {}
  10.  
  11. local count = 0
  12. local countMax = 10000
  13.  
  14. local function doYield()
  15.   os.queueEvent("Yielder")
  16.   os.pullEvent("Yielder")
  17.   count = 0
  18. end
  19.  
  20. function funcs.yieldizeFunction(f)
  21.   return function(...)
  22.     count = count + 1
  23.     if count > countMax then
  24.       doYield()
  25.     end
  26.     return f(...)
  27.   end
  28. end
  29.  
  30. function funcs.yieldize(tbl)
  31.   for k, v in pairs(tbl) do
  32.     if type(v) == "function" then
  33.       tbl[k] = funcs.yieldizeFunction(v)
  34.     end
  35.   end
  36. end
  37.  
  38. function funcs.setMax(x)
  39.   countMax = x
  40. end
  41.  
  42. function funcs.reset()
  43.   count = 0
  44. end
  45.  
  46. return funcs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement