#OOP

1 messages · Page 1 of 1 (latest)

median kestrel
#

It's traumatizing me

Metatables, __index

vale ruin
#

same bro same

indigo geode
#

skill issue

dawn pewter
#

lol

stable drift
# median kestrel It's traumatizing me Metatables, __index

you need to understand how metatables work

__index is one of the metamethods that exists

__index can be either a table or a function that receives self, key

basically the use of __index is this:

you got your table set to a metatable:

local t = setmetatable({}, metaTable);

local k = t["test"]

imagine metaTable has a __index set to another table, what will happen is this:

  • Will try to see if the key exists on the table
  • If it does not exists, it will get the metatable of the table and if it owns the __index metamethod it will try to find the key in the table of the index metamethod
stable drift
indigo geode
#

if ur wondering how i did that: \\\_\\\_index