lua-users home
lua-l archive

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


On Thu, 20 Dec 2001, Joshua Jensen wrote:

> I'm wondering why you chose to only make the event tables (handler
> tables) available to tag methods only?  That is:
>
> Events =
> {
> 	Var = 5
> }
>
> MyTable =
> {
> 	Var = 10
> }
>
> eventtable(MyTable, Events)
>
> print(MyTable.Var)
> print(eventtable(MyTable).Var)
>
> As I have stated in previous postings, having these handler tables
> available for storing functions can save considerably on memory.  Sure,
> I can put whatever functions I want in the handler table, but I have to
> use the ugly syntax in the second print() above to access the data.

You can use inheritance (delegation) for that, as we have always done in Lua:

Events = { print = function (self) print(self.x) end }
Events.index = Events

MyTable = {x = 0}
eventtable(MyTable, Events)

MyTable:print()

-- Roberto