这为什么会导致C栈溢出?

3

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

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

local x = setmetatable({}, mt)

x.y = 5
1个回答

4

深度递归.

在调用元方法__newindex时,self[key] = value会再次递归地调用元方法__newindex,直至堆栈溢出。


啊,我明白了。谢谢。 - David

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接