This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Slappy826's profile picture

Terminal Glasses Auto-Sync

Started by Slappy826, 21 June 2015 - 08:46 PM
Slappy826 #1
Posted 21 June 2015 - 10:46 PM
I was making a script for terminal glasses and thought i would just release this.
what it basicly does is you can use the fake table to do stuff like


syncGlass.addText(2,2,"Auto-synced!",0xffffff)

and it will automatically go to the client without calling the sync function.

(if you dont like this format just tell me, i wrote this up real quick and will edit it later if you request so.)

Pastebin: http://pastebin.com/y2YbvJxf

function getGlass(g)
local function wrapObject(thing)
  return setmetatable({},{
   __index = function(s,i)
	if(type(thing[i]) == 'function')then
	 return function(...)
	  local stuf = thing[i](...)
	  g.sync()
	  return stuf
	 end;
	else
	 return thing[i]
	end
   end;
  })
end
local fakeg = setmetatable({},{
  __index = function(s,i)
   if(type(g[i]) == 'function')then
	return function(...)--//#wrapped
	 return (function() local a = wrapObject(g[i](...)) g.sync() return(a) end)()
	end
   else
	return g[i]
   end
  end;
})
return fakeg
end
--//
local glass = peripheral.wrap("left")
local syncGlass = getGlass(glass)
AnonymousDapper #2
Posted 22 June 2015 - 05:54 AM
Neat.
Slappy826 #3
Posted 22 June 2015 - 07:34 PM
Thanks :)/>