There is no such thing as a "variable stored in userdata", At least, not as far as Lua is concerned. From Lua's perspective, userdata is a giant black box. All Avatar.testVar = 5
does is call the metamethod __newindex
in Avatar
with the string testVar
and the new value 15
. How your C++ metamethod (because only C++ code can put metamethods on userdata) interprets this is entirely up to your code.
So it can't be done from Lua. Your code will need to provide debugging hooks. Lua 5.2 allows you to implement the __pairs
and __ipairs
metamethods, which the pairs
and ipairs
functions can use to iterate over your values. Outside of that, you're on your own for querying what does and doesn't exist in a userdata.