Forum
CS2D Scripts What's __ and self.__index?What's __ and self.__index?
2 replies 1
https://www.lua.org/pil/16.html
"__index" key works just like any other key would work if you put it within a regular table, but it is a different scenario if you put it within a table that is going to be used as a metatable. There are metamethods for metatables just for the sake of dramatically changing their behaviours, and I stress the word dramatically there. "__index" is just one of those metamethods which is, if you ask me, best for inheritance and such. It is a plain function that is triggered when a key is checked in the table, of course, if that specific table has been set a metatable with this metamethod.
It is kinda tricky to explain it but pretty sure this would tell you something: https://www.lua.org/pil/13.4.1.html
Metatables and metamethods can be hard to learn at first, but once grasped, you are going to be questioning many possibilities with them.
1