Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

table.insert doesn't invoke __newindex?

Asked by
LuaQuest 450 Moderation Voter
8 years ago

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.

0
bump NewVoids 97 — 6y

Answer this question