Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function NewStack(t)
- local Stack = {
- size_of = function(self)
- local size_of=#self
- return size_of
- end,
- push = function(self, ...)
- for _, v in ipairs{...} do
- self[#self+1] = v
- end
- end,
- pop = function(self, num)
- local num = num or 1
- if num > #self then
- return nil
- --error("underflow in NewStack-created stack")
- end
- local ret = {}
- for i = num, 1, -1 do
- ret[#ret+1] = table.remove(self)
- end
- return unpack(ret)
- end
- }
- return setmetatable(t or {}, {__index = Stack})
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement