Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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,},},}
- function writeNewFunc(Func, File)
- -- Func has to be a table!
- local file = readFileToTable(File)
- local Lines = Index.Lines
- table.insert(file, tonumber(Lines)," ")
- Lines = Lines + 1
- local funcStart = tonumber(Lines - 1)
- for i=1,#Func do
- table.insert(file, tonumber(Lines + i - 1),tostring(Func[i]))
- end
- local funcEnd = Lines + #Func
- local funcName = string.sub(tostring(Func[1]),10, string.find(Func[1], "%(")-1)
- table.insert(Index["Functions"], {Name = tostring(funcName), LineA = tonumber(funcStart), LineE = tonumber(funcEnd)})
- Index.Lines = funcEnd
- file[1] = tostring("Index="..textutils.serialize(Index))
- saveTableToFile(file, File)
- end
- function saveTableToFile(Table, File)
- local file = fs.open(tostring(File), "w")
- for i=1,#Table do
- file.writeLine(tostring(Table[i]))
- end
- file.close()
- end
- function readFileToTable(File)
- local l = 1
- local file = {}
- f = fs.open(tostring(File), "r")
- while true do
- local Line = f.readLine()
- if Line then
- table.insert(file, l, tostring(Line))
- l = l + 1
- else
- break
- end
- end
- f.close()
- return file
- end
- function deleteFunc(Name, File)
- local num = 0
- local Lines = 0
- local file = readFileToTable(File)
- for i=1,#Index["Functions"] do
- if tostring(Index["Functions"][i]["Name"]) == tostring(Name) then
- Lines = Index["Functions"][i]["LineE"] - Index["Functions"][i]["LineA"]
- for j=Index["Functions"][i]["LineA"], Index["Functions"][i]["LineE"] do
- table.remove(file, Index["Functions"][i]["LineA"])
- end
- table.remove(Index["Functions"], num)
- num = i
- break
- end
- end
- Index.Lines = Index.Lines - Lines
- file[1] = tostring("Index="..textutils.serialize(Index))
- saveTableToFile(file, File)
- end
- function runOrder(Order)
- Error = {pcall(loadstring(Order))}
- print(textutils.serialize(Error))
- return {Error}
- end
- function modemWatch(side, channel)
- local modem = peripheral.wrap(side)
- modem.open(channel)
- local Event = {os.pullEvent("modem_message")}
- if string.find(tostring(Event[5]), "Order:", 1) then
- local Linx, Liny = string.find(tostring(Event[5]), "Order:", 1)
- local Order = tostring(string.sub(tostring(Event[5]),Liny + 1))
- modem.close(channel)
- runOrder(Order)
- else
- return Event
- end
- end
- function test()
- error("Hallo", 2)
- end
Advertisement
Add Comment
Please, Sign In to add comment