Advertisement
melzneni

sys_syslib

Feb 9th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. function string:split(s, delimiter)
  2. local result = {};
  3. for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
  4. table.insert(result, match);
  5. end
  6. return result;
  7. end
  8.  
  9. function getMsgData(msg)
  10. local i, j = string.find(msg, ":")
  11. local tag = string.sub(msg, 1, i - 1)
  12. local pts = string:split(string.sub(msg,i+1,-1), ",")
  13. return tag,pts
  14. end
  15.  
  16. --syslib end
  17.  
  18. rednet.open("back")
  19. function identify()
  20. rednet.broadcast("@root:identify")
  21. end
  22.  
  23. identify()
  24. while true do
  25. local id, message = rednet.receive()
  26. local tag, pts = getMsgData(message)
  27. if tag == "root" then
  28. if pts[1] == "initialise" then
  29. identify()
  30. else print("unknown fromRoot-msg: ", tag)
  31. end
  32. else
  33. print("unknown msg-tag: ", tag)
  34. end
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement