我对使用"."的以下两种语法感到困惑.
根据我的理解,__index当一个键不存在于表中但存在于其元表中时调用.那么为什么列表会调用__index然后将其自身分配给list.__index?
list = {}
list.__index = list
setmetatable(list, { __call = function(_, ...)
local t = setmetatable({length = 0}, list)
for _, v in ipairs{...} do t:push(v) end
return t
end })
function list:push(t)
if self.last then
self.last._next = t
t._prev = self.last
self.last = t
else
self.first = t
self.last = t
end
self.length = self.length + 1
end
.
.
.
local l = list({ 2 }, {3}, {4}, { 5 …Run Code Online (Sandbox Code Playgroud)