Is it even possible to do this thorugh metamethods? or would i have to try something else.
My original response
__index only triggers through metatables:
local t = {}
t.__index = function(self, index) --function that runs when a value is indexed
print("Table indexed:", index) --prints the name of index
end
local metatable = setmetatable({}, t) --sets the metatable of a blank table
local indexTest = metatable.Index --test index
Re-reading your question, Iām a bit puzzled. Are you asking how to get the script line that triggered the __index metamethod?
Yes that is what i am asking.
I think debug.info is what you are looking for.
This example code prints 9, which is the number of the line t[1] = t[1]
.
local mt = {}
function mt:__index(k, v)
print(debug.info(2, "l"))
end
local t = {}
setmetatable(t, mt)
t[1] = t[1]
1 Like