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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -