How metatables work and what they're used for?

Hello. Can you explain how metatables work, and what they’re used for?
I tried to understand it but I still can not.

2 Likes

There’s so many tutorials and videos you could have searched for instead of blatantly asking.

They work via metamethods which are usually binded to a function within a table set to be the metatable of a table, these metamethods are then invoked when you do a certain something with the table connected to the metatable.

For example, if you try to index something that doesn’t exist, the metamethod __index is invoked. Read the Developer Hub for more info.

2 Likes

Thank you. Your explanation was very clear and helpful! :slight_smile:

1 Like