lua-users home
lua-l archive

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


Title: __index metamethod

This code doesn’t invoke the __index metamethod.

tt = {'a', 'b', 'cc'}

mt = {

  __newindex = function(table, key, value)

                    error("Attempt to modify read-only table")

                  end,

 __index = function(table, key, value)

                    error("Attempt to access read-only table")

                  end,

}

setmetatable(tt, mt)

tt[2] = 1


I don’t understand exactly why..

-------------------

Sean Riley

"All problems in computer science can be solved by another level of indirection", Butler Lampson, 1972