【发布时间】:2017-02-01 20:26:41
【问题描述】:
我尝试在 Lua 中进行基本继承,但我不太明白为什么在我对 print() 的调用中,以下内容没有索引表 mt.prototype。
local x = {}
mt = {}
mt.prototype = {
value = 5,
}
mt = {
__index = function (table, key)
return mt.prototype[key]
end,
}
setmetatable(x, mt)
print(x.value)
它说mt.prototype 不存在,但我不明白为什么。
【问题讨论】: