lua-users home
lua-l archive

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

Yes matter of taste. I must admit I use the Lua API as a kind of toolkit in
my C code and I do use a Lua table internally in the same way as you have
from Lua. Of course, the object-oriented version of 'Delegate_List' could be
implemented in pure Lua. As you might guess 'Delegate_List' inherits
generalised list handling methods (like add) from a parent class 'List'.
Providing a __call metamethod for Delegate_List is rather neat, I think,
whether done in C or in Lua and it means from C you simply pcall the
delegate object itself (or treat it like a function in Lua).

-----Original Message-----
From: Bulat Ziganshin [] 
Sent: 01 June 2009 13:48
To: John Hind
Cc: 'Lua list'
Subject: Re[2]: Lua Event driven programming

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
> 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)

  -- event1 handler

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

Best regards,