Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fs = require("filesystem")
- local shell = require("shell")
- local component = require("component")
- local args = shell.parse(...)
- if (#args < 1) then
- print("use: recipe <item>")
- end
- local item = args[1]
- function getRecipe(item)
- local fname = string.gsub(item, ":", "_")
- if (not fs.exists("/home/satori/recipe/" .. fname)) then
- return -1
- end
- local file = io.open(fname, "r")
- local text = file:read("*all")
- local w = "([%a:0]+)"
- local regexp = w .. " " .. w
- .. " " .. w .. "\n"
- .. w .. " " .. w .. " " .. w .. "\n"
- .. w .. " " .. w .. " " .. w
- --print(regexp)
- local _, _,
- i1, i2, i3,
- i4, i5, i6,
- i7, i8, i9
- = string.find(text, regexp)
- local ans = {
- i1, i2, i3, i4, i5, i6, i7, i8, i9
- }
- file:close()
- return ans
- end
- local testItems = getRecipe(item)
- if (testItems == (-1)) then print ("no such item in database") return end
- function getDeps(handledRecipe)
- local need = {}
- for i=1,#handledRecipe do
- if (handledRecipe[i] ~= "0") then
- need[handledRecipe[i]] = 0
- end
- end
- for i=1,#handledRecipe do
- if (handledRecipe[i] ~= "0") then
- need[handledRecipe[i]] = need[handledRecipe[i]] + 1
- end
- end
- return need
- end
- local need = getDeps(testItems)
- for a,b in pairs(need) do
- print(a .. ": " .. b)
- local r = getRecipe(a)
- if (r ~= -1) then
- print("or " .. b .. "x")
- for c,d in pairs(getDeps(r)) do
- print(c .. ": " .. d)
- end
- end
- end
- local storage = component.proxy(component.list("controller")(0))
- local robot = component.proxy(component.list("robot")(0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement