How to get line in which __index metamethod trigges

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