feat(cargo-elevator): implement high-level functions
Still need the smaller details.
This commit is contained in:
parent
9a8f81e428
commit
b60bb94e07
1 changed files with 61 additions and 0 deletions
61
cargo-elevator.lua
Normal file
61
cargo-elevator.lua
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
-- program to manage a cargo elevator
|
||||
-- yes, i am aware i could just use the computer to transfer packages at this
|
||||
-- point, but where's the fun in that?
|
||||
|
||||
local FLOORS = {
|
||||
{
|
||||
match = function (input)
|
||||
local first_char = string.sub(input, 1, 1)
|
||||
return first_char == "A" or first_char == "W"
|
||||
end,
|
||||
detect = function ()
|
||||
-- TODO
|
||||
end,
|
||||
call = function ()
|
||||
-- TODO
|
||||
end
|
||||
storage = "",
|
||||
elevator_storage = "",
|
||||
}
|
||||
}
|
||||
|
||||
local SLEEP_T = 5
|
||||
|
||||
local PKG_STACK = {
|
||||
transfer_all = function (self, src, dest)
|
||||
-- TODO
|
||||
end,
|
||||
transfer_matching = function (self, src, dest, match_f)
|
||||
-- TODO
|
||||
end,
|
||||
get_next_floor = function (self)
|
||||
-- TODO
|
||||
end
|
||||
stack = {},
|
||||
}
|
||||
|
||||
function run (floors, stack)
|
||||
local next_addr = nil
|
||||
for _, floor in pairs(floors) do
|
||||
if floor.detect() then
|
||||
stack:transfer_all(floor.storage, floor.elevator_storage)
|
||||
stack:transfer_matching(
|
||||
floor.elevator_storage, floor.storage, floor.match
|
||||
)
|
||||
next_addr = stack:get_next_floor()
|
||||
end
|
||||
end
|
||||
if next_addr ~= nil then
|
||||
for _, floor in pairs(floors) do
|
||||
if floor.match(next_addr) then
|
||||
floor.call()
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
run(FLOORS)
|
||||
os.sleep(SLEEP_T)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue