What do the two arguments mean in a function inside a metatable.
Something like this:
local mt = setmetatable({},{
__index = function(t,k) --- what is t and what is k
}
)
What do the two arguments mean in a function inside a metatable.
Something like this:
local mt = setmetatable({},{
__index = function(t,k) --- what is t and what is k
}
)
Quick example
local mt = setmetatable({},{
__index = function(t,k) --- what is t and what is k
print(t,k)
end
}
)
print(mt.E)--mt table, "E" and then ... Nil
Those arguments are the indexed table and the index
In that case, t is the variable “mt” (keep in mind setmetatable returns the original table, not the metatable) and k is the key you index it with. It’s different for different metamethods, though, so I’d check the wiki whenever you’re unsure.