home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 January / Gamestar_69_2005-01_dvd.iso / Dema / theprojectv1-0.exe / FCData / Scripts.pak / Scripts / methoddispatcher.lua < prev   
Encoding:
Text File  |  2004-07-21  |  814 b   |  43 lines

  1. MethodDispatcherPool={
  2.     _pool={},
  3. };
  4.  
  5. function MethodDispatcherPool:AddObj(obj,idx)
  6.     local _idx=obj;
  7.     if(idx)then
  8.         _idx=idx;
  9.     end
  10.     self._pool[_idx]=obj;
  11. end
  12.  
  13. function MethodDispatcherPool:RemoveObject(idx)
  14.     self._pool[idx]=nil;
  15. end
  16.  
  17. function MethodDispatcherPool:Exists(idx)
  18.     return self._pool[idx];
  19. end
  20.  
  21. function MethodDispatcherPool.IndexHandler(table,index)
  22.     local f = function(...)
  23.         local pool=%table._pool
  24.         for i,val in pool do
  25.             local pool_func=val[%index];
  26.             if(pool_func)then
  27.                 arg[1]=val;
  28.                 call(pool_func,arg);
  29.             end
  30.         end
  31.     end
  32.     table[index]=f;
  33.     return f;
  34. end
  35.  
  36. function MethodDispatcherPool:new()
  37.     local mmp=new(MethodDispatcherPool);
  38.     local tag=newtag()
  39.     settagmethod(tag,"index",MethodDispatcherPool.IndexHandler);
  40.     settag(mmp,tag);
  41.     return mmp;
  42. end
  43.