Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR LUA

Lua Stack

-- OOP boilerplate - create a class, add __index, then make a constructor
Stack = {}
Stack.__index = Stack
function Stack.new() return setmetatable({}, Stack) end
 
-- put a new object onto a stack
function Stack:push(input)
	self[#self+1] = input
end
-- take an object off a stack
function Stack:pop()
	assert(#self > 0, "Stack underflow")
	local output = self[#self]
	self[#self] = nil
	return output
end
Source by developer.roblox.com #
 
PREVIOUS NEXT
Tagged: #Lua #Stack
ADD COMMENT
Topic
Name
5+2 =