View Single Post
08-09-13, 01:55 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Billtopia View Post
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.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote