3

我知道我可以通过使用来解决这个问题rawset,但我只是想知道为什么下面的代码会导致 C 堆栈溢出。

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

local x = setmetatable({}, mt)

x.y = 5
4

1 回答 1

4

深度递归

在对 metamethod 的调用中,再次递归调用 metamethod __newindex,直到堆栈溢出。self[key] = value__newindex

于 2014-10-25T06:59:33.603 回答