local Stack = {} Stack.__index = Stack function Stack.new() return setmetatable({ items = {} }, Stack) end function Stack:push(v) table.insert(self.items, v) end function Stack:pop() return table.remove(self.items) end function Stack:size() return #self.items end local s = Stack.new() s:push("a"); s:push("b") print(s:size()) print(s:pop()) print(s:pop()) print(s:pop()) print(s:size())