Hello, i am watching this: Maze Programming and i am trying to translate this line off c++ code
stack<pair<int, int>> m_stack;
this is what i have so far but i am stumped
self.Make_Pair = function(x, y)
end
this is the stack module
local Stack = {}
local StackMt = {__index = Stack}
function Stack.new()
local self = {}
return setmetatable(self, StackMt)
end
-- puch an object into a stack
function Stack:push(input)
self[#self+1] = input
end
-- remove an object from a stack
function Stack:pop()
assert(#self >0, "Stack underflow")
local output = self[#self]
self[#self] = nil
return output
end
return Stack
Are you trying to make a stack data structure module or a stack of pairs? I’m not very experienced with c++, but after some research a pair is also a data structure.
Sorry for posting on this fairly old topic, but those are vectors in C++. You’d have to include the vector header files and get the standard namespace library. Now to do that in Lua, I’m not sure. There are many possible ways, but the one I think is the best is creating an array of the same types, or a dictionary with a metatable.