Advertisement
Guest User

Untitled

a guest
Jan 24th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. function NewStack(t)
  2. local Stack = {
  3. size_of = function(self)
  4. local size_of=#self
  5. return size_of
  6. end,
  7. push = function(self, ...)
  8. for _, v in ipairs{...} do
  9. self[#self+1] = v
  10. end
  11. end,
  12. pop = function(self, num)
  13. local num = num or 1
  14. if num > #self then
  15. return nil
  16. --error("underflow in NewStack-created stack")
  17. end
  18. local ret = {}
  19. for i = num, 1, -1 do
  20. ret[#ret+1] = table.remove(self)
  21. end
  22. return unpack(ret)
  23. end
  24. }
  25. return setmetatable(t or {}, {__index = Stack})
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement