lua-users home
lua-l archive

__index metamethod

[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


AltStyle によって変換されたページ (->オリジナル) /