I'm trying to make a transparant metatable, this is easy enough to do with the meta-methods __index and __newindex, however, iterating over this table is giving me some problems...
Is it possible to make this work... That is, I know the list of "meta"-indices that I want to have in the table - and want ipairs / pairs to iterate over this list.
Right now, using
gives nothing, since I have no where to put the list..
If we consider Nick's usage of metatables to access MushClient variables using __index and __newindex, this would be equivalent to being able to iterate over all the variables - doing another workaround to make
be equivalent to:
My best work-around so far has been to use the __call metamethod and returning the list there, but this is error-prone - and it's non-intuitive to people who aren't aware of the table being a "pseudo" table. The result looking something like:
Any bright ideas? :-)
Thanks,
- Rasmus.
Is it possible to make this work... That is, I know the list of "meta"-indices that I want to have in the table - and want ipairs / pairs to iterate over this list.
Right now, using
for x, y in pairs(pseudo_table) do
print(x)
end
gives nothing, since I have no where to put the list..
If we consider Nick's usage of metatables to access MushClient variables using __index and __newindex, this would be equivalent to being able to iterate over all the variables - doing another workaround to make
for k, v in pairs(var) do
Note (k, " = ", v)
end
be equivalent to:
for k, v in pairs(GetVariableList()) do
Note (k, " = ", v)
end
My best work-around so far has been to use the __call metamethod and returning the list there, but this is error-prone - and it's non-intuitive to people who aren't aware of the table being a "pseudo" table. The result looking something like:
for k, v in pairs(var()) do
Note (k, " = ", v)
end
Any bright ideas? :-)
Thanks,
- Rasmus.