Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local filesystem = require"filesystem"
- local keyboard = require"keyboard"
- local r = {}
- local com = require"component"
- r.nfsopen = function(file,mode)
- local file = io.open(file,mode)
- file.online = 1
- if(mode == "r")then
- file.readLine = function()
- local ind = 1
- for lines in file:lines() do
- if file.online == ind then
- file.online = file.online + 1
- return lines
- else
- ind = ind + 1
- end
- end
- end
- file.readAll = function()
- local cont = ""
- for lines in file:lines() do
- cont = cont .. lines
- end
- return cont
- end
- elseif(mode == "w")then
- file.dowrite = file.write
- file.writestr = ""
- file.write = function(str)
- file.writestr = file.writestr .. str
- end
- file.writeLine = function(line)
- file:dowrite(line .. "\n")
- end
- end
- local oldclose = file.close
- file.close = function()
- if(file.writestr ~= nil)then
- file:dowrite(file.writestr)
- end
- oldclose(file)
- end
- return file
- end
- r.shell = require"shell"
- r.shell.dir = r.shell.getWorkingDirectory
- r.shell.setDir = r.shell.setWorkingDirectory
- r.shell.isColor = function() return true end
- r.unpack = table.unpack
- r.os = os
- r.unpack = table.unpack
- r.term = require"term"
- colors = require"colors"
- term = require"term"
- r.write = term.write
- r.term.getSize = com.gpu.getResolution
- r.os.pullEvent = function(ev)
- local tmatrix = {
- ['mouse_click'] = "touch",
- ['mouse_drag'] = "drag",
- ['mouse_scroll'] = "scroll",
- ['key'] = "key_down",
- }
- local ccmatrix = {
- ['touch'] = "mouse_click",
- ['drag'] = "mouse_drag",
- ['scroll'] = "mouse_scroll",
- ['key_down'] = "key",
- }
- if(tmatrix[ev] ~= nil)then ev = tmatrix[ev] end
- local rev = {require"event".pull(ev)}
- if(ccmatrix[rev[1]] ~= nil)then rev[1] = ccmatrix[rev[1]] end
- if(rev[1] == "key" or rev[1] == "key_up" or rev[1] == "key_down")then
- rev[2] = rev[4]
- end
- if(rev[1]:find("mouse"))then
- if(rev[1] == "mouse_click" or rev[1] == "mouse_drag")then
- rev[5] = rev[5] + 1
- end
- if(rev[1] == "mouse_scroll")then
- rev[5] = rev[5] * -1
- end
- rev[2] = rev[5]
- table.remove(rev,5)
- end
- return table.unpack(rev)
- end
- r.sleep = os.sleep
- r.paintutils = require"paintutils"
- r.term.setCursorPos = term.setCursor
- r.term.getCursorPos = term.getCursor
- r.term.setBackgroundColor = com.gpu.setBackground
- r.term.getBackgroundColor = com.gpu.getBackground
- r.term.setTextColor = com.gpu.setForeground
- r.term.getTextColor = com.gpu.getForeground
- r.term.current = function() return {setVisible = function(bool) end} end
- r.read = term.read
- newcolors = {
- ['white'] = 0xF0F0F0,
- ['orange'] = 0xF2B233,
- ['magenta'] = 0xE57FD8,
- ['lightBlue'] = 0x99B2F2,
- ['yellow'] = 0xDEDE6C,
- ['lime'] = 0x7FCC19,
- ['pink'] = 0xF2B2CC,
- ['gray'] = 0x4C4C4C,
- ['lightGray'] = 0x999999,
- ['cyan'] = 0x4C99B2,
- ['purple'] = 0xB266E5,
- ['blue'] = 0x3366CC,
- ['brown'] = 0x7F664C,
- ['green'] = 0x57A64E,
- ['red'] = 0xCC4C4C,
- ['black'] = 0x000000,
- }
- r.colors = newcolors
- -- Loading apis and stuff --
- r.loadfile = function( _sFile, _tEnv )
- local file = fs.open( _sFile, "r" )
- if file then
- local func, err = load( file.readAll(), fs.getName( _sFile ), "t", _tEnv )
- file.close()
- return func, err
- end
- return nil, "File not found"
- end
- r.dofile = function( _sFile )
- local fnFile, e = r.loadfile( _sFile, _G )
- if fnFile then
- return fnFile()
- else
- error( e, 2 )
- end
- end
- function r.os.run( _tEnv, _sPath, ... )
- local tArgs = { ... }
- local tEnv = _tEnv
- setmetatable( tEnv, { __index = _G } )
- local fnFile, err = r.loadfile( _sPath, tEnv )
- if fnFile then
- local ok, err = pcall( function()
- fnFile( table.unpack( tArgs ) )
- end )
- if not ok then
- if err and err ~= "" then
- error( err )
- end
- return false
- end
- return true
- end
- if err and err ~= "" then
- error( err )
- end
- return false
- end
- _G['tAPIsLoading'] = {}
- function r.os.loadAPI( _sPath )
- local sName = filesystem.name( _sPath )
- if _G['tAPIsLoading'][sName] == true then
- error( "API "..sName.." is already being loaded" )
- return false
- end
- _G['tAPIsLoading'][sName] = true
- local tEnv = {}
- setmetatable( tEnv, { __index = _G } )
- local fnAPI, err = r.loadfile( _sPath, tEnv )
- if fnAPI then
- local ok, err = pcall( fnAPI )
- if not ok then
- error( err )
- _G['tAPIsLoading'][sName] = nil
- return false
- end
- else
- error( err )
- _G['tAPIsLoading'][sName] = nil
- return false
- end
- local tAPI = {}
- for k,v in pairs( tEnv ) do
- if k ~= "_ENV" then
- tAPI[k] = v
- end
- end
- _G[sName] = tAPI
- _G['tAPIsLoading'][sName] = nil
- return true
- end
- function r.os.unloadAPI( _sName )
- if _sName ~= "_G" and type(_G[_sName]) == "table" then
- _G[_sName] = nil
- end
- end
- r.ccdefs_unload = function(self)
- colors = require"colors"
- self.fs = nil
- self.unpack = nil
- self.keys = nil
- paintutils = nil
- write = nil
- keys = nil
- fs = nil
- os = nil
- isCC = nil
- read = nil
- r.nfsopen = nil
- r.shell = require"shell"
- r.shell.dir = nil
- r.shell.setDir = nil
- r.unpack = table.unpack
- r.term = require"term"
- colors = require"colors"
- term = require"term"
- r.write = nil
- term.getSize = nil
- r.os = nil
- os = require"os"
- sleep = nil
- paintutils = nil
- term.setCursorPos = nil
- term.getCursorPos = nil
- term.setBackgroundColor = nil
- term.getBackgroundColor = nil
- term.setTextColor = nil
- term.getTextColor = nil
- term.current = nil
- read = nil
- end
- r.init = function(self)
- colors = newcolors
- paintutils = self.paintutils
- write = self.write
- self.fs = {
- open = self.nfsopen,
- isDir = filesystem.isDirectory,
- exists = filesystem.exists,
- copy = filesystem.copy,
- list = function(_Path)
- local files = {}
- for file in filesystem.list(_Path) do
- files[#files+1] = file
- end
- return files
- end,
- move = filesystem.rename,
- delete = filesystem.remove,
- getName = filesystem.name,
- }
- self.unpack = table.unpack
- self.keys = keyboard.keys
- self.keys.leftCtrl = keyboard.keys.lcontrol
- self.keys.rightCtrl = keyboard.keys.rcontrol
- keys = self.keys
- fs = self.fs
- os = self.os
- sleep = os.sleep
- isCC = function() return true end
- r.read = function(pwdchar)
- return term.read(nil,nil,nil,pwdchar)
- end
- ccdefs_unload = function() r:ccdefs_unload() end
- read = self.read
- table.unpack(self)
- end
- return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement