|
For debugging outputs I have occasionally wanted to ask a variable its name. I don't know a direct way to do this but I notice that the type of the values given to __index are a table and a string.
Following that lead I discovered that the following will give me a variable's name as a string
> tricktable = {__index = function (_,v) return v end}
> setmetatable(tricktable, tricktable)
> a = 1
> =a
1
> =tricktable.a
a
> =type(tricktable.a)
string