Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local fileName = args[1]
- local debugKey = keys.f2
- local running = true
- local programIsRunning = true
- local env = {}
- local fileContent = {}
- local handle = fs.open(fileName,"r")
- local sLine = handle.readLine()
- while sLine do
- fileContent[#fileContent+1] = sLine:gsub("local","") --make all variables global
- sLine = handle.readLine()
- end
- handle.close()
- local handle = fs.open(".debug_file","w")
- for k,v in pairs(fileContent) do
- handle.writeLine(v.."\n")
- end
- handle.close()
- local function run()
- dofile(".debug_file")
- end
- setfenv(run, env)
- local function debug()
- while true do
- sleep(0)
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- term.setCursorPos(1,1)
- for key,var in pairs(env) do
- print(key, " = ", var)
- end
- end
- end
- local runCo = coroutine.create(run)
- local debugCo = coroutine.create(debug)
- coroutine.resume(runCo)
- while running do
- local evt = {os.pullEvent()}
- if evt[1] == "key"and evt[2] == debugKey then
- programIsRunning = not programIsRunning
- end
- if programIsRunning then
- if coroutine.status(runCo) ~= "dead" then
- coroutine.resume(runCo, unpack(evt))
- end
- else
- if coroutine.status(debugCo) ~= "dead" then
- coroutine.resume(debugCo, unpack(evt))
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment