Originally Posted by Billtopia
I was wondering if a generic for ( in pairs ) can walk over values in a metatable from the parent table?
I can find nothing anywhere on if this can be done or if pairs can only walk the given table and not its metatable?
|
Consider:
Code:
local f = CreateFrame("Frame")
for k, v in pairs(f) do
print(k, "is a", type(v))
end
From that, you will only get one print: "0 is a userdata"
Code:
local f = CreateFrame("Frame")
local mt = getmetatable(f)
for k, v in pairs(mt) do
print(k, "is a", type(v))
end
That will get you "__index is a table".
Code:
local f = CreateFrame("Frame")
local mt = getmetatable(f)
local index = mt.__index
for k, v in pairs(index) do
print(k, "is a", type(v))
end
Now you'll finally get all the Frame object methods, eg. "IsMovable is a function".
The same principles apply to any table and its metatable. If you want to look at the metatable, you have to use
getmetatable and look at it directly.
If you want a real suggestion for solving your actual problem, you'll have to actually describe what that problem is. I don't know why half the questions people post lack any context whatsoever... it just makes it impossible to answer without resorting to guesses and tangents.