lua-users home
lua-l archive

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

I didn't fully understand Lua metatable mechanism.

I tought that the following example would allow me to use a table as if it was a function (note that there are two metatables):

mmt = {}
mmt.__index = mmt
function mmt.__call(tab,...) 
   print("called: ",tab,unpack(arg))

mt = {}
mt.__index = mmt

tab = {}

Now, even if getmetatable(tab).__call is a function the instruction tab("xx") will fail. Reading the reference manual more carefully I noticed it states that "access to a metamethod does not invoke other metamethods" and that this is the expected behaviour. 

What I don't understand is the reason why. Efficiency? I would have found this feature very useful.


P.S. The same goes for __add etc.