Advertisement
colddddda

Untitled

Apr 27th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1. _lock=function(class)
  2. class=class:sub(1,1):upper()..class:sub(2);
  3. local object=Instance.new(class);
  4. return function(props)
  5. if(type(list_base_props)=='table')then
  6. for i,v in next,list_base_props do
  7. if(props[i]==nil)then
  8. props[i]=v;
  9. end;
  10. end;
  11. end;
  12.  
  13. local proxy,meta,cons,redo,works,_real,_redo,_connect,_setup,_lock_f,_obj;
  14.  
  15. proxy=newproxy(true);
  16. meta=getmetatable(proxy);
  17.  
  18. cons={};
  19. works={};
  20.  
  21. --begin functions------------------------------------
  22. _real=function(proxy)
  23. if(getmetatable(proxy)=='drezmor_object')then
  24. return proxy();
  25. else
  26. return proxy;
  27. end;
  28. end;
  29. _lock_f=function(fun)
  30. getfenv(fun).this=proxy;
  31. end;
  32. _connect=function(add,event,fun,index)
  33. pcall(_lock_f,fun);
  34. local c=object[event]:connect(fun);
  35.  
  36. if(not cons[event])then
  37. cons[event]={};
  38. end;
  39. if(index)then
  40. cons[event][index].connect:disconnect();
  41. cons[event][index].connect=c;
  42. elseif(add)then
  43. cons[event][#cons[event]+1]={
  44. connect=c;
  45. fun=fun;
  46. };
  47. end;
  48.  
  49. return c,#cons[event];
  50. end;
  51. _obj=function(...)
  52. local a,b=...;
  53. local count=select('#',...);
  54. if(count==0)then
  55. return object;
  56. elseif(count==1)then
  57. return object[a],a;
  58. elseif(count==2)then
  59. works[a]=true;
  60. object[a]=b;
  61. works[a]=false;
  62. end;
  63. end;
  64. --end functions--------------------------------------
  65.  
  66. --begin properties-----------------------------------
  67. do
  68. local new_props={};
  69. for index,value in next,props do
  70. local load,res,key=pcall(_obj,index:sub(1,1):upper()..index:sub(2));
  71. if(not load)then
  72. load,res,key=pcall(_obj,index);
  73. end;
  74.  
  75. if(load)then
  76. local vt=type(value);
  77. local vm=getmetatable(res);
  78. local rt=type(res);
  79. local rs=tostring(res);
  80.  
  81. if(rt=='userdata'and rs=='Signal '..key)then
  82. if(vt=='table')then
  83. for i=1,#value do
  84. _connect(true,key,value[i]);
  85. end;
  86. else
  87. _connect(true,key,value);
  88. end;
  89. else
  90. if(vt~='function'and vm~='drezmor_object')then
  91. new_props[key]=function()return value;end;
  92. else
  93. new_props[key]=value;
  94. end;
  95. end;
  96. end;
  97. end;
  98. props=new_props;
  99. end;
  100. --end properties-------------------------------------
  101.  
  102. --begin setup----------------------------------------
  103. _redo=function(p)
  104. if(not works[p]and props[p])then
  105. works[p]=true;
  106. wait(0.001);
  107.  
  108. if(not pcall(_obj,p,props[p]())and p=='Parent')then
  109. _setup();
  110. end;
  111.  
  112. works[p]=false;
  113. end;
  114. end;
  115. _setup=function()
  116. object=Instance.new(class);
  117.  
  118. if(redo)then
  119. redo:disconnect();
  120. end;
  121.  
  122. for event,infos in next,cons do
  123. for i=1,#infos do
  124. _connect(false,event,infos[i].fun,i);
  125. end;
  126. end;
  127.  
  128. for i,v in next,props do
  129. _obj(i,v());
  130. end;
  131.  
  132. works=nil;
  133. works={};
  134.  
  135. redo=object.Changed:connect(_redo);
  136.  
  137. return proxy;
  138. end;
  139. --end setup---------------------------------------
  140.  
  141. --begin metatable---------------------------------
  142. meta.__metatable='drezmor_object';
  143.  
  144. meta.__call=function(self,...)
  145. return _obj(...);
  146. end;
  147.  
  148. meta.__tostring=function()
  149. return tostring(object);
  150. end;
  151.  
  152. meta.__len=function()
  153. return#object:children();
  154. end;
  155.  
  156. meta.__newindex=function(self,k,n)
  157. local load,res,key=pcall(_obj,k:sub(1,1):upper()..k:sub(2));
  158. if(not load)then
  159. load,res,key=pcall(_obj,k);
  160. end;
  161.  
  162. if(load)then
  163. local rt=type(res);
  164. local rs=tostring(res);
  165.  
  166. if(rt=='userdata'and rs=='Signal '..key)then
  167. _connect(true,key,n);
  168. else
  169. if(type(n)~='function'and getmetatable(n)~='drezmor_object')then
  170. props[key]=function()return n;end;
  171. else
  172. props[key]=n;
  173. end;
  174. _obj(key,_real(n));
  175. end;
  176. end;
  177. end;
  178.  
  179. meta.__index=function(self,k)
  180. local load,res,key=pcall(_obj,k:sub(1,1):upper()..k:sub(2));
  181. if(not load)then
  182. load,res,key=pcall(_obj,k);
  183. end;
  184.  
  185. if(load)then
  186. local rt=type(res);
  187. local rs=tostring(res);
  188.  
  189. if(rt=='function')then
  190. return key:lower()=='destroy'and function(self,...)
  191. if(self==proxy)then
  192. _setup=nil;
  193. redo:disconnect();
  194. for i,v in next,cons do
  195. for i=1,#v do
  196. v[i].connect:disconnect();
  197. end;
  198. end;
  199. proxy,meta,cons,redo,works,_real,_redo,_connect,_setup,_lock_f,_obj=
  200. nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil;
  201. object:Destroy(...);
  202. else
  203. self:Destroy(...);
  204. end;
  205. end or function(self,...)
  206. res(_real(self),...);
  207. end;
  208. elseif(rt=='userdata'and rs=='Signal '..key)then
  209. local t;t={
  210. disconnect=function()
  211. if(cons[key])then
  212. for i,v in next,cons[key]do
  213. v.connect:disconnect();
  214. end;
  215. cons[key]=nil;
  216. end;
  217. end;
  218.  
  219. connect=function(self,fun)
  220. if(self==t)then
  221. local c,i=_connect(true,key,fun);
  222. local ct;ct={
  223. disconnect=function(self,...)
  224. if(self==ct)then
  225. c:disconnect(...);
  226. if(cons[key]and cons[key][i]and cons[key][i].fun==fun)then
  227. cons[key][i].connect:disconnect();
  228. cons[key][i]=nil;
  229. end;
  230. else
  231. self:disconnect(...);
  232. end;
  233. end;
  234. };
  235. return ct;
  236. else
  237. return self:connect(fun);
  238. end;
  239. end;
  240.  
  241. wait=function(self,...)
  242. if(self==t)then
  243. return res:wait(...);
  244. else
  245. return self:wait(...);
  246. end;
  247. end;
  248. };
  249. return t;
  250. else
  251. return object[key];
  252. end;
  253. end;
  254. end;
  255. --end metatable-----------------------------------
  256.  
  257. if(type(list_drezmor_objects)=='table')then
  258. list_drezmor_objects[#list_drezmor_objects+1]=proxy;
  259. end;
  260.  
  261. return _setup();
  262. end;
  263. end;
  264.  
  265. --test-----------------------------------------------------------------------------
  266.  
  267. this=_lock'hint'{
  268. parent=workspace;
  269. text='test';
  270. changed=function(p)
  271. print(p,this);
  272. end;
  273. };
  274.  
  275. wait(5);
  276.  
  277. this.changed:disconnect();
  278.  
  279. wait(5);
  280.  
  281. this:destroy();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement