Skip to content

Instantly share code, notes, and snippets.

@kylelk
Forked from nefftd/stackexample.lua
Created December 16, 2014 07:45
Show Gist options
  • Save kylelk/9815d328cde77aa518f9 to your computer and use it in GitHub Desktop.
Save kylelk/9815d328cde77aa518f9 to your computer and use it in GitHub Desktop.
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