Nathan1852

NatAPI

Dec 30th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. Index={["Lines"]=88,["Functions"]={[1]={["LineE"]=28,["Name"]="saveTableToFile",["LineA"]=22,},[2]={["LineE"]=45,["Name"]="readFileToTable",["LineA"]=30,},[3]={["LineE"]=20,["Name"]="writeNewFunc",["LineA"]=3,},},}
  2.  
  3. function writeNewFunc(Func, File)
  4. -- Func has to be a table!
  5. local file = readFileToTable(File)
  6. local Lines = Index.Lines
  7. table.insert(file, tonumber(Lines)," ")
  8. Lines = Lines + 1
  9. local funcStart = tonumber(Lines - 1)
  10. for i=1,#Func do
  11. table.insert(file, tonumber(Lines + i - 1),tostring(Func[i]))
  12. end
  13. local funcEnd = Lines + #Func
  14. local funcName = string.sub(tostring(Func[1]),10, string.find(Func[1], "%(")-1)
  15. table.insert(Index["Functions"], {Name = tostring(funcName), LineA = tonumber(funcStart), LineE = tonumber(funcEnd)})
  16. Index.Lines = funcEnd
  17. file[1] = tostring("Index="..textutils.serialize(Index))
  18. saveTableToFile(file, File)
  19. end
  20.  
  21. function saveTableToFile(Table, File)
  22. local file = fs.open(tostring(File), "w")
  23. for i=1,#Table do
  24. file.writeLine(tostring(Table[i]))
  25. end
  26. file.close()
  27. end
  28.  
  29. function readFileToTable(File)
  30. local l = 1
  31. local file = {}
  32. f = fs.open(tostring(File), "r")
  33. while true do
  34. local Line = f.readLine()
  35. if Line then
  36. table.insert(file, l, tostring(Line))
  37. l = l + 1
  38. else
  39. break
  40. end
  41. end
  42. f.close()
  43. return file
  44. end
  45.  
  46. function deleteFunc(Name, File)
  47. local num = 0
  48. local Lines = 0
  49. local file = readFileToTable(File)
  50. for i=1,#Index["Functions"] do
  51. if tostring(Index["Functions"][i]["Name"]) == tostring(Name) then
  52. Lines = Index["Functions"][i]["LineE"] - Index["Functions"][i]["LineA"]
  53. for j=Index["Functions"][i]["LineA"], Index["Functions"][i]["LineE"] do
  54. table.remove(file, Index["Functions"][i]["LineA"])
  55. end
  56. table.remove(Index["Functions"], num)
  57. num = i
  58. break
  59. end
  60. end
  61. Index.Lines = Index.Lines - Lines
  62. file[1] = tostring("Index="..textutils.serialize(Index))
  63. saveTableToFile(file, File)
  64. end
  65.  
  66. function runOrder(Order)
  67. Error = {pcall(loadstring(Order))}
  68. print(textutils.serialize(Error))
  69. return {Error}
  70. end
  71.  
  72. function modemWatch(side, channel)
  73. local modem = peripheral.wrap(side)
  74. modem.open(channel)
  75. local Event = {os.pullEvent("modem_message")}
  76. if string.find(tostring(Event[5]), "Order:", 1) then
  77. local Linx, Liny = string.find(tostring(Event[5]), "Order:", 1)
  78. local Order = tostring(string.sub(tostring(Event[5]),Liny + 1))
  79. modem.close(channel)
  80. runOrder(Order)
  81. else
  82. return Event
  83. end
  84. end
  85.  
  86. function test()
  87. error("Hallo", 2)
  88. end
Advertisement
Add Comment
Please, Sign In to add comment