61 lines
1.4 KiB
Lua
61 lines
1.4 KiB
Lua
-- 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
|