Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local program = table.remove( tArgs, #tArgs )
- local numThing
- numThing = {
- __add = function( left, right )
- if type( left ) == "table" then
- local new = {}
- if type( right ) == "table" then
- for k, v in pairs( left ) do
- new[ k ] = v + right[ k ]
- end
- elseif type( right ) == "number" then
- for k, v in pairs( left ) do
- new[ k ] = v + right
- end
- end
- return setmetatable( new, numThing )
- else
- return right + left
- end
- end,
- __sub = function( left, right )
- if type( left ) == "table" then
- local new = {}
- if type( right ) == "table" then
- for k, v in pairs( left ) do
- new[ k ] = v - right[ k ]
- end
- elseif type( right ) == "number" then
- for k, v in pairs( left ) do
- new[ k ] = v - right
- end
- end
- return setmetatable( new, numThing )
- else
- return -right + left
- end
- end,
- __mul = function( left, right )
- if type( left ) == "table" then
- local new = {}
- if type( right ) == "table" then
- for k, v in pairs( left ) do
- new[ k ] = v * right[ k ]
- end
- elseif type( right ) == "number" then
- for k, v in pairs( left ) do
- new[ k ] = v * right
- end
- end
- return setmetatable( new, numThing )
- else
- return right * left
- end
- end,
- __div = function( left, right )
- if type( left ) == "table" then
- local new = {}
- if type( right ) == "table" then
- for k, v in pairs( left ) do
- new[ k ] = v / right[ k ]
- end
- elseif type( right ) == "number" then
- for k, v in pairs( left ) do
- new[ k ] = v / right
- end
- end
- return setmetatable( new, numThing )
- else
- local new = {}
- if type( left ) == "number" then
- for k, v in pairs( right ) do
- new[ k ] = left / v
- end
- end
- return setmetatable( new, numThing )
- end
- end,
- __concat = function( left, right )
- return tostring( left ) .. tostring( right )
- end,
- __tostring = function( self )
- return tostring( self.term )
- end,
- __eq = function( left, right )
- if type( left ) == "table" then
- if type( right ) == "table" then
- for k, v in pairs( left ) do
- if not right[ k ] == v then
- return false
- end
- end
- return true
- elseif type( right ) == "number" then
- return left.term == right
- end
- else
- return right == left
- end
- end,
- __lt = function( left, right )
- if type( left ) == "table" then
- if type( right ) == "table" then
- for k, v in pairs( left ) do
- if not right[ k ] < v then
- return false
- end
- end
- return true
- elseif type( right ) == "number" then
- return left.term < right
- end
- else
- return right > left
- end
- end,
- __le = function( left, right )
- if type( left ) == "table" then
- if type( right ) == "table" then
- for k, v in pairs( left ) do
- if not v <= right[ k ] then
- return false
- end
- end
- return true
- elseif type( right ) == "number" then
- return left.term <= right
- end
- else
- return right >= left
- end
- end,
- __unm = function( self )
- return 0 - self
- end,
- __len = function( self )
- return #tostring( self )
- end,
- }
- local current = term.current()
- local _redirect = {
- setCursorPos = function( x, y )
- if type( x ) == "table" and type( y ) == "table" then
- for _, monitor in ipairs( tArgs ) do
- peripheral.call( monitor, "setCursorPos", x[ monitor ], y[ monitor ] )
- end
- elseif type( x ) == "table" and type( y ) == "number" then
- for _, monitor in ipairs( tArgs ) do
- peripheral.call( monitor, "setCursorPos", x[ monitor ], y )
- end
- elseif type( x ) == "number" and type( y ) == "table" then
- for _, monitor in ipairs( tArgs ) do
- peripheral.call( monitor, "setCursorPos", x, y[ monitor ] )
- end
- elseif type( x ) == "number" and type( y ) == "number" then
- for _, monitor in ipairs( tArgs ) do
- peripheral.call( monitor, "setCursorPos", x, y )
- end
- end
- current.setCursorPos( type( x ) == "number" and x or x.term, type( y ) == "number" and y or y.term )
- end,
- setTextColor = function( color )
- for _, monitor in ipairs( tArgs ) do
- peripheral.call( monitor, "setTextColor", color )
- end
- current.setTextColor( color )
- end,
- setTextColour = function( color )
- for _, monitor in ipairs( tArgs ) do
- peripheral.call( monitor, "setTextColor", color )
- end
- current.setTextColor( color )
- end,
- setBackgroundColor = function( color )
- for _, monitor in ipairs( tArgs ) do
- peripheral.call( monitor, "setBackgroundColor", color )
- end
- current.setBackgroundColor( color )
- end,
- setBackgroundColour = function( color )
- for _, monitor in ipairs( tArgs ) do
- peripheral.call( monitor, "setBackgroundColor", color )
- end
- current.setBackgroundColor( color )
- end,
- isColor = function()
- for _, monitor in ipairs( tArgs ) do
- if not peripheral.call( monitor, "isColor" ) then
- return false
- end
- end
- return true
- end,
- isColour = function()
- for _, monitor in ipairs( tArgs ) do
- if not peripheral.call( monitor, "isColour" ) then
- return false
- end
- end
- return true
- end,
- getSize = function()
- local x, y = {}, {}
- for _, monitor in ipairs( tArgs ) do
- x[ monitor ], y[ monitor ] = peripheral.call( monitor, "getSize" )
- end
- x.term, y.term = current.getSize()
- return setmetatable( x, numThing ), setmetatable( y, numThing )
- end,
- getCursorPos = function()
- local x, y = {}, {}
- for _, monitor in ipairs( tArgs ) do
- x[ monitor ], y[ monitor ] = peripheral.call( monitor, "getCursoPos" )
- end
- x.term, y.term = current.getCursorPos()
- return setmetatable( x, numThing ), setmetatable( y, numThing )
- end,
- clear = function()
- for _, monitor in ipairs( tArgs ) do
- peripheral.call( monitor, "clear" )
- end
- current.clear()
- end,
- }
- term.redirect( _redirect )
- term.clear()
- shell.run( program )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement