Stack_Tips.lua 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by xxn.
  4. --- DateTime: 2020/10/13 10:28
  5. ---
  6. Stack = {}
  7. Stack.__index = Stack
  8. local tinsert = table.insert
  9. function Stack:New()
  10. local o = {dataTb = {}}
  11. setmetatable(o, self)
  12. return o
  13. end
  14. function Stack:Push(...)
  15. local arg = {...}
  16. self.dataTb = self.dataTb or {}
  17. if next(arg) then
  18. for i = 1, #arg do
  19. tinsert(self.dataTb, arg[i])
  20. end
  21. end
  22. end
  23. function Stack:Pop(num)
  24. num = num or 1
  25. assert(num > 0, "num必须为正整数")
  26. local popTb = {}
  27. for i = 1, num do
  28. tinsert(popTb, self.dataTb[#self.dataTb])
  29. table.remove(self.dataTb)
  30. end
  31. return unpack(popTb)
  32. end
  33. function Stack:Peek()
  34. return self.dataTb[#self.dataTb]
  35. end
  36. function Stack:List()
  37. for i = #self.dataTb, 1, -1 do
  38. logOrange(i, self.dataTb[i].name, self.dataTb[i].logicTbl.rank)
  39. end
  40. end
  41. function Stack:Count()
  42. return #self.dataTb
  43. end
  44. function Stack:IsEmpty()
  45. return #self.dataTb == 0
  46. end