Created
December 16, 2014 07:33
-
-
Save nefftd/023d94188ee076cf3f67 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(1) -- 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
there is a typo on line 22 it should be
s:push(i)