lua - How to use __index as a function? -
i'm trying imitate:
b = {1,2,3} = setmetatable({1,nil,3},{__index = b}) print(a[2]) -- prints 2
with that:
b = {1,2,3} = setmetatable({1,nil,3},{__index = function(t,k) rawget(b,k) end}) print(a[2]) -- nil
what did wrong?
you need return value in metamethod:
return rawget(b,k)
Comments
Post a Comment