Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if pocket then
- os.pullEventRaw = function(sEvent)
- local file = fs.open(".async","r")
- local hadLines = false
- for line in file.readLine do
- os.queueEvent("task_complete",unpack(textutils.unserialize(line)))
- hadLines = true
- end
- if hadLines then fs.open(".async","w").close() end
- return coroutine.yield(sEvent)
- end
- commands = {
- list = function()
- local file = fs.open(".code","r")
- local cmd = textutils.unserialize(file.readLine())
- table.insert(cmd.exec,"return commands.list()")
- file.close()
- file = fs.open(".code","w")
- file.writeLine(textutils.serialize(cmd):gsub("\n",""))
- file.close()
- while true do
- file = fs.open(".exec","r")
- local output = file.readLine()
- if output then
- file.close()
- fs.open(".exec","w").close()
- return textutils.unserialize(output)[1]
- end
- file.close()
- sleep(0.0)
- end
- end,
- exec = function(sCommand)
- assert(type(sCommand)=="string" or not sCommand,"string expected got "..type(sCommand))
- local file = fs.open(".code","r")
- local cmd = textutils.unserialize(file.readLine())
- table.insert(cmd.exec,"os.setComputerLabel("..((os.computerLabel()=="Command Pocket Computer" or os.computerLabel()==nil) and "" or ("[["..os.computerLabel().."]]"))..") return commands.exec([["..sCommand.."]])")
- file.close()
- file = fs.open(".code","w")
- file.writeLine(textutils.serialize(cmd):gsub("\n",""))
- file.close()
- while true do
- file = fs.open(".exec","r")
- local output = file.readLine()
- if output then
- file.close()
- fs.open(".exec","w").close()
- return unpack(textutils.unserialize(output))
- end
- file.close()
- sleep(0.05)
- end
- end,
- execAsync = function(sCommand)
- assert(type(sCommand)=="string" or not sCommand,"string expected got "..type(sCommand))
- local file = fs.open(".code","r")
- local cmd = textutils.unserialize(file.readLine())
- table.insert(cmd.async,"os.setComputerLabel("..((os.computerLabel()=="Command Pocket Computer" or os.computerLabel()==nil) and "" or ("[["..os.computerLabel().."]]"))..") return commands.execAsync([["..sCommand.."]])")
- file.close()
- file = fs.open(".code","w")
- file.writeLine(textutils.serialize(cmd):gsub("\n",""))
- file.close()
- end,
- getBlockPosition = function()
- local file = fs.open(".code","r")
- local cmd = textutils.unserialize(file.readLine())
- table.insert(cmd.exec,"return commands.getBlockPosition()")
- file.close()
- file = fs.open(".code","w")
- file.writeLine(textutils.serialize(cmd):gsub("\n",""))
- file.close()
- while true do
- file = fs.open(".exec","r")
- local output = file.readLine()
- if output then
- file.close()
- fs.open(".exec","w").close()
- return unpack(textutils.unserialize(output))
- end
- file.close()
- sleep(0.05)
- end
- end,
- getBlockInfo = function(x,y,z)
- local file = fs.open(".code","r")
- local cmd = textutils.unserialize(file.readLine())
- table.insert(cmd.exec,"return commands.getBlockInfo("..x..","..y..","..z..")")
- file.close()
- file = fs.open(".code","w")
- file.writeLine(textutils.serialize(cmd):gsub("\n",""))
- file.close()
- while true do
- file = fs.open(".exec","r")
- local output = file.readLine()
- if output then
- file.close()
- fs.open(".exec","w").close()
- return unpack(textutils.unserialize(output))
- end
- file.close()
- sleep(0.05)
- end
- end,
- async = {},
- }
- local tbl = commands.list()
- for _,k in ipairs(tbl) do
- commands[k] = function(sCommand)
- assert(type(sCommand)=="string" or not sCommand,"string expected got "..type(sCommand))
- local file = fs.open(".code","r")
- local cmd = textutils.unserialize(file.readLine())
- table.insert(cmd.exec,"os.setComputerLabel("..((os.computerLabel()=="Command Pocket Computer" or os.computerLabel()==nil) and "" or ("[["..os.computerLabel().."]]"))..") return commands."..k.."([["..sCommand.."]])")
- file.close()
- file = fs.open(".code","w")
- file.writeLine(textutils.serialize(cmd):gsub("\n",""))
- file.close()
- while true do
- file = fs.open(".exec","r")
- local output = file.readLine()
- if output then
- file.close()
- fs.open(".exec","w").close()
- return unpack(textutils.unserialize(output))
- end
- file.close()
- sleep(0.05)
- end
- end
- commands.async[k] = function(sCommand)
- assert(type(sCommand)=="string" or not sCommand,"string expected got "..type(sCommand))
- local file = fs.open(".code","r")
- local cmd = textutils.unserialize(file.readLine())
- table.insert(cmd.async,"os.setComputerLabel("..((os.computerLabel()=="Command Pocket Computer" or os.computerLabel()==nil) and "" or ("[["..os.computerLabel().."]]"))..") return commands.async."..k.."([["..sCommand.."]])")
- file.close()
- file = fs.open(".code","w")
- file.writeLine(textutils.serialize(cmd):gsub("\n",""))
- file.close()
- end
- end
- else
- if not fs.exists(".code") then
- local file = fs.open(".code","w")
- file.writeLine(textutils.serialize({exec={},async={}}):gsub("\n",""))
- file.close()
- fs.open(".async","w").close()
- fs.open(".exec","w").close()
- end
- foo = function()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- term.write("name: ")
- input = read()
- commands.async.give(input.." ComputerCraft:pocketComputer 1 1 {display:{Name:Command Pocket Computer},computerID:"..os.computerID().."}")
- sleep(0.0)
- end
- end
- bar = function()
- while true do
- local file = fs.open(".code","r")
- local cmd = textutils.unserialize(file.readLine())
- if cmd then
- for i=1,#cmd.exec do
- output = {loadstring(cmd.exec[i])()}
- local execFile = fs.open(".exec","a")
- execFile.writeLine(textutils.serialize(output):gsub("\n",""))
- execFile.close()
- end
- for i=1,#cmd.async do
- output = {loadstring(cmd.async[i])()}
- local asyncFile = fs.open(".async","a")
- asyncFile.writeLine(textutils.serialize(output):gsub("\n",""))
- asyncFile.close()
- end
- end
- file.close()
- file = fs.open(".code","w")
- file.write(textutils.serialize({exec={},async={}}):gsub("\n",""))
- file.close()
- sleep(0.1)
- end
- end
- while true do
- parallel.waitForAny(foo,bar)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement