Guest User

Untitled

a guest
Jun 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. -- Replace this function with your "new" function
  2. local function NewItem()
  3. return { }
  4. end
  5.  
  6. -- Storage of released items
  7. local pool = {}
  8.  
  9. -- Get/create a new item
  10. local function Acquire()
  11. local item = next(pool)
  12. if not item then
  13. item = NewItem()
  14. else
  15. pool[item] = nil
  16. end
  17. return item
  18. end
  19.  
  20. -- Release an item to the pool
  21. local function Release(item)
  22. if pool[item] then
  23. error("Attempt to release a item that was already released")
  24. end
  25. pool[item] = true
  26. end
Add Comment
Please, Sign In to add comment