✓ Accepted answer
I think here you trying is to print a, b and c. I don't know if it was the self of the table the key and the value but whatever I write the other thing you can do, enjoy !
I change something but you can change it back and if you want to learn more with metatables, just go one wiki here
soo here the code for printting all thing:
local meta={
__index=function(a, b, c)
return {'a', 'b', 'c'}
end
}
local tab = setmetatable({}, meta)
newtab = tab[1]
print(table.concat(newtab, ', '))
or if you want to see what is the table Adress they key and the value of the table, do this:
local meta={
__index=function(self, key, value)
return {self, key, value}
end
}
local tab = setmetatable({}, meta)
newtab = tab[1]
print(newtab[1], newtab[2], newtab[3])
1 comment
Metamethods in Lua 5.1 are limited to returning only 1 value; hence, 'b' and 'c' will not be returned unless, as xToonLinkX123 stated, you pack all values you want to return into an array.