-
-
Save kylelk/9815d328cde77aa518f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local Stack = {} | |
Stack.__index = Stack | |
function Stack:push(value) | |
table.insert(self,value) | |
end | |
function Stack:pop() | |
return table.remove(self) | |
end | |
function Stack:new() | |
local new = {} | |
setmetatable(new,self) | |
return new | |
end | |
local s = Stack:new() | |
for i = 1,10 do | |
s:push(i) -- we use : now, not . | |
end | |
local a = s:pop() | |
while a do | |
print(a) | |
a = s:pop() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment