So I've noticed something that seems very strange to me. Apparently table.insert does not invoke the __newindex metamethod, for reasons I don't understand. For example:
local t = setmetatable({},{ __newindex = function(t,k,v) rawset(t,k,v) -- set the values to the table without causing a stack overflow print'The newindex metamethod has been invoked.' end }) t[1] = 'Hello' -- Output: 'The newindex metamethod has been invoked.' table.insert(t,'Hello again') -- Output: Nothing
Could it be that these build-in functions aren't in Lua, and metamethods only detect changes inside Lua? Or could i be way off. Anyway, if someone has more understanding about this than i do, I'd appreciate an answer. Thanks for reason.