Advertisement
robn

Untitled

Aug 17th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1. EventQueue = {
  2.     Create = function (name)
  3.         local events = {}
  4.         local callbacks = {}
  5.  
  6.          EventQueue["on"..name] = {
  7.             Connect = function (cb)
  8.                 callbacks[cb] = cb
  9.             end,
  10.  
  11.             Disconnect = function (cb)
  12.                 callbacks[cb] = nil
  13.             end,
  14.  
  15.             DebugTimer = function (enabled)
  16.                 -- implement this
  17.             end,
  18.  
  19.             Queue = function (...)
  20.                 table.insert(events, {...})
  21.             end,
  22.  
  23.             Signal = function (...)
  24.                 local e = {...}
  25.                 for i = 1, #callbacks do
  26.                     callbacks[i](unpack(e))
  27.                 end
  28.             end,
  29.  
  30.             Emit = function ()
  31.                 while #events > 0 do
  32.                     local e = events.remove(events, 1)
  33.                     for i = 1, #callbacks do
  34.                         callbacks[i](unpack(e))
  35.                     end
  36.                 end
  37.             end,
  38.  
  39.             ClearEvents = function ()
  40.                 events = {}
  41.             end,
  42.         }
  43.    end
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement