lua-users home
lua-l archive

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



(I hope I get the OO terminology right.) If I want to tell a table t to be an instance of a class c, it seems that there are many choices. What are the pros and cons of each of these, for example:

 t.__index = c
 setmetatable(t,t)

or:

 setmetatable(t,{__index=c})

or, after making c the target of its own metatable's __index in either of the above two ways, this:

 setmetatable(t,c)


The first seems the most visibly self-documenting; the second seems the purest (but needs another table for every instance); the third seems to be a bit of both.

What does the received wisdom of the list say?