Implement base TurtleController and simple VolumeExcavationController
This commit is contained in:
48
lib/stack.lua
Normal file
48
lib/stack.lua
Normal file
@ -0,0 +1,48 @@
|
||||
---@class Stack
|
||||
---@field elements table[]
|
||||
local Stack = {}
|
||||
Stack.__index = Stack
|
||||
|
||||
|
||||
---@return Stack
|
||||
function Stack:Create()
|
||||
-- stack table
|
||||
local t = {}
|
||||
setmetatable(t, Stack)
|
||||
|
||||
-- entry table
|
||||
t.elements = {}
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
---@param element table
|
||||
function Stack:Push(element)
|
||||
if element == nil or element == {} then
|
||||
return
|
||||
end
|
||||
|
||||
table.insert(self.elements, element)
|
||||
end
|
||||
|
||||
|
||||
---@return table
|
||||
function Stack:Pop()
|
||||
return table.remove(self.elements)
|
||||
end
|
||||
|
||||
|
||||
---@return table
|
||||
function Stack:Peek()
|
||||
return table[#self.elements]
|
||||
end
|
||||
|
||||
|
||||
---@return number
|
||||
function Stack:Count()
|
||||
return #self.elements
|
||||
end
|
||||
|
||||
|
||||
return Stack
|
||||
Reference in New Issue
Block a user