Heres the gist
module
local T = {}
function T:Print()
print("Printed")
end
local layer = setmetatable({}, {
__index = function(Index)
T[Index]()
end})
script
require(themodule):Print()
Heres the gist
module
local T = {}
function T:Print()
print("Printed")
end
local layer = setmetatable({}, {
__index = function(Index)
T[Index]()
end})
script
require(themodule):Print()
Any ideas or something
I need to figure this out badly
The first argument of the __index
metamethod is the table that’s being indexed, and it passes a second string value that is what you’re looking for.
__index(table, index) Fires when table[index] is indexed, if table[index] is nil. Can also be set to a table, in which case that table will be indexed.
wtf can you make an example of that being done
The above would work because the second argument Index
has the index that was used in the normal script.
The value of tab
here is just an empty table: {}
. That’s because tab is the table that the metatable got set to on line 5.