Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- CCPresenter by TheOriginalBIT
- Version 1.0
- First Created: 22 March 2013
- Last Updated: 23 March 2013
- Inspired by, and continuation of: http://www.computercraft.info/forums2/index.php?/topic/11003-remote-presentation/
- ]]
- local args = {...}
- local function stop(msg)
- _G.ccpresenter_loaded = false
- term.restore()
- print('Stopping service...')
- rednet.broadcast('service_closed')
- sleep(1)
- end
- if #args == 1 and args[1] == '-stop' then -- restore the term so nothing more is sent
- stop()
- return
- elseif #args == 1 and args[1] == '-reset' then -- developer use only, reloads the program
- stop()
- elseif #args > 0 then -- if an arg has been supplied and its not valid or there are too many args
- printError('invalid runtime argument(s) supplied')
- return
- end
- -- if this program has been run before, exit, it doesn't need to be run all the time since
- if _G.ccpresenter_loaded then
- print('Service already started...')
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- return
- end
- -- error without line numbers and stuff
- _G.nonVerboseError = function(msg) printError(msg) error() end
- _G.findPeripheral = function( t ) for _,s in pairs(rs.getSides()) do if peripheral.getType(s) == t then return s end end nonVerboseError('No '..t..' attached to the computer') end
- _G.sendPacket = function(method, ...) rednet.broadcast(textutils.serialize({ _m = method, _a = {...} })) end
- -- make a term object and redirect to it
- termObj = setmetatable({}, {__index = term.native})
- termObj.scroll = function(n)
- term.native.scroll(n)
- sendPacket('scroll', n)
- end
- termObj.setCursorPos = function(x,y)
- term.native.setCursorPos(x,y)
- sendPacket('setCursorPos', x, y)
- end
- termObj.write = function( ... )
- term.native.write( ... )
- sendPacket('write', ...)
- end
- termObj.clear = function()
- term.native.clear()
- sendPacket('clear')
- end
- termObj.clearLine = function()
- term.native.clearLine()
- sendPacket('clearLine')
- end
- -- only add the colour functions when they are in the term api, this allows support for pre-cc1.4
- if term.setTextColor then
- termObj.setTextColor = function(c)
- term.native.setTextColor(c)
- sendPacket('setTextColor', c)
- end
- termObj.setTextColour = termObj.setTextColor
- end
- -- only add the colour functions when they are in the term api, this allows support for pre-cc1.4
- if term.setBackgroundColor then
- termObj.setBackgroundColor = function(c)
- term.native.setBackgroundColor(c)
- sendPacket('setBackgroundColor', c)
- end
- termObj.setBackgroundColour = termObj.setBackgroundColor
- end
- termObj.setCursorBlink = function(b)
- term.native.setCursorBlink(b)
- sendPacket('setCursorBlink', b)
- end
- _G.ccpresenter_loaded = true
- print('Starting up service...')
- sleep(1)
- term.redirect( termObj )
- rednet.open( findPeripheral( 'modem' ) )
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement