Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open "top"
- local function split(str, sep)
- local t = {}
- for sub in str:gmatch("[^" .. sep .. "]+") do
- table.insert(t, sub)
- end
- return t
- end
- local function query(m)
- local msg
- repeat
- rednet.broadcast(m, "mw")
- _, msg = rednet.receive("mw", 1)
- until msg
- return msg
- end
- print "Multiplexed Warehousing: CLI Terminal"
- while true do
- write "|> "
- local tokens = split(read(), " ")
- local cmd = table.remove(tokens, 1)
- if cmd == "w" then
- local fst = table.remove(tokens, 1)
- local qty = tonumber(fst)
- if not qty then
- table.insert(tokens, fst)
- qty = math.huge
- end
- local item = table.concat(tokens, " ")
- local sources, hasFound, result = {}, 0
- repeat
- result = query { cmd = "find", dname = item }
- if result then
- table.insert(sources, { result[1], result[2] })
- hasFound = hasFound + result[3].count
- end
- until hasFound >= qty or not result
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement