From 2ff57086e22bab108c963b25d082e388a1ab3709 Mon Sep 17 00:00:00 2001 From: Cody Young Date: Tue, 21 Mar 2023 00:01:59 -0500 Subject: [PATCH] Add pipe_driver --- test-programs/logistics-pipes/pipe_driver.lua | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test-programs/logistics-pipes/pipe_driver.lua diff --git a/test-programs/logistics-pipes/pipe_driver.lua b/test-programs/logistics-pipes/pipe_driver.lua new file mode 100644 index 0000000..a08e305 --- /dev/null +++ b/test-programs/logistics-pipes/pipe_driver.lua @@ -0,0 +1,51 @@ +local component = require("component") + +local driver = {} + +-------------------------------------------------------------------------------- +---------------------------------- Item Class ---------------------------------- +-------------------------------------------------------------------------------- + +local ItemStack = {} + +function ItemStack.new(item) + checkARg(1, item, "table"); + local out = { + data = item.getValue1(), + quantity = item.getValue2() + } + setmetatable(out, ItemStack) + return out +end + +function ItemStack:getName() + return self.data.getName() +end + +-------------------------------------------------------------------------------- +-------------------------------- Private Driver -------------------------------- +-------------------------------------------------------------------------------- + + +driver.internal = {} + +-------------------------------------------------------------------------------- +-------------------------------- Public Driver -------------------------------- +-------------------------------------------------------------------------------- + +function driver.getItems() + if not component.isAvailable("logisticspipe") then + error("no logistics pipe available", 2) + end + local pipe = component.logisticspipe.getPipe() + if not pipe.getAvailableItems and not pipe.makeRequest then + error("Logistics pipe is not a a requesting pipe") + end + local output = {} + for _,item in pairs(pipe.getAvailableItems()) do + table.insert(output, ItemStack.new(item)) + end + return output +end + +return driver