lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello John,

Monday, June 1, 2009, 4:22:05 PM, you wrote:

> I created a Lua class implemented in C called "Delegate_List" which
> maintains a list of functions (the event handlers) and a metatable override
> for the Lua call operation makes a call on objects of this class call all
> the functions in the list in turn

just my two pennies: i hate to do any data manipulation in C
so for handling multiple event handlers i does the same in Lua:

handlers = {}
function add_handler(event,handler)
  handlers[event] = append (handlers[event] or {},  handler)
end

add_handler("event1",
  function(obj)
  -- event1 handler
  end)

-- Called from C in case of event
function event1(obj)
  for _,v in ipairs(handlers.event1 or {})
    v(obj)
  end
end




-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin@gmail.com