ronkrt

Untitled

Jun 17th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. -- Computer portion!
  2. function main()
  3. term.clear()
  4. x,y = term.getSize()
  5. term.setCursorPos(1,1)
  6. term.setCursorBlink(true)
  7. print("Welcome to turtlemine!")
  8. OpenAllPorts()
  9. Input()
  10. end
  11. function OpenAllPorts()
  12. for _,v in ipairs(rs.getSides()) do
  13. rednet.open(v)
  14. end
  15. end
  16. function Input()
  17. while true do
  18. term.write("mine > ")
  19. local x = read()
  20. if(string.lower(x)=="exit") then
  21. break
  22. end
  23. rednet.broadcast(x)
  24. end
  25. end
  26. main()
  27.  
  28. -- Miner portion!
  29. function main()
  30. OpenAllPorts()
  31. while true do
  32. local id,request = rednet.receive()
  33. print(request)
  34. local args = split(request," ")
  35. local program = args[1]
  36. table.remove(args,1)
  37. shell.run(program,cunpack(args))
  38. end
  39. end
  40. function OpenAllPorts()
  41. for _,v in ipairs(rs.getSides()) do
  42. rednet.open(v)
  43. end
  44. end
  45. function split(x,sep)
  46. local sep, fields = sep or ":", {}
  47. local pattern = string.format("([^%s]+)", sep)
  48. x:gsub(pattern, function(c) fields[#fields+1] = c end)
  49. return fields
  50. end
  51. function cunpack(t,pk)
  52. local k,v = next(t,pk)
  53. if k ~= nil then
  54. return v,cunpack(t,k)
  55. end
  56. end
  57. main()
Advertisement
Add Comment
Please, Sign In to add comment