Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图模仿:
b = {1,2,3} a = setmetatable({1,nil,3},{__index = b}) print(a[2]) -- prints 2
接着就,随即:
b = {1,2,3} a = setmetatable({1,nil,3},{__index = function(t,k) rawget(b,k) end}) print(a[2]) -- nil
我做错什么了?
您需要在元方法中返回一个值:
return rawget(b,k)