Why does this cause a C stack overflow?

I know I can fix this problem using rawset

, but I'm just wondering why the following code is causing a C stack overflow.

local mt = {
    __newindex = function(self, key, value) 
        self[key] = value 
    end
}

local x = setmetatable({}, mt)

x.y = 5

      

+3


source to share


1 answer


Deep recursion .



Inside a call to a metamethod __newindex

, self[key] = value

it calls the metamethod again __newindex

, recursively, before.

+4


source







All Articles