Advertisement
Guest User

startup.lua

a guest
Apr 11th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. rednet.open "top"
  2.  
  3. local function split(str, sep)
  4.     local t = {}
  5.     for sub in str:gmatch("[^" .. sep .. "]+") do
  6.         table.insert(t, sub)
  7.     end
  8.     return t
  9. end
  10.  
  11. local function query(m)
  12.     local msg
  13.     repeat
  14.         rednet.broadcast(m, "mw")
  15.         _, msg = rednet.receive("mw", 1)
  16.     until msg
  17.     return msg
  18. end
  19.  
  20. print "Multiplexed Warehousing: CLI Terminal"
  21. while true do
  22.     write "|> "
  23.     local tokens = split(read(), " ")
  24.     local cmd = table.remove(tokens, 1)
  25.    
  26.     if cmd == "w" then
  27.         local fst = table.remove(tokens, 1)
  28.         local qty = tonumber(fst)
  29.        
  30.         if not qty then
  31.             table.insert(tokens, fst)
  32.             qty = math.huge
  33.         end
  34.        
  35.         local item = table.concat(tokens, " ")
  36.         local sources, hasFound, result = {}, 0
  37.         repeat
  38.             result = query { cmd = "find", dname = item }
  39.             if result then
  40.                 table.insert(sources, { result[1], result[2] })
  41.                 hasFound = hasFound + result[3].count
  42.             end
  43.         until hasFound >= qty or not result
  44.        
  45.        
  46.     end
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement