In lua 4.0 the tagmethod "gettable" allows to intercept the access to table elements. Each time there is an attempt to access a table element, the linked tagmethod for "gettable" event is called:
local t = { a=123 }
local tg = newtag()
settagmethod(tg, "gettable",
function(tbl, idx) print(tbl, idx) return rawget(tbl, idx) end )
settag(t, tg)
print(t.a) -- <-- prints table: 0x7f9a8250acc0 a
-- <-- then prints t.a value
What is the equivalent in Lua 5.xx ?
How can my code call a method each time the table is accessed in Lua 5.x?