Getting list of attributes of a luabind class created in Lua

494 Views Asked by At

Lua classes can be created using the OO system that Luabind exposes to Lua:

http://www.rasterbar.com/products/luabind/docs.html#defining-classes-in-lua

class 'MyClass'
function MyClass:__init()    
    self.a1 = true
    self.a2 = "MyClass"
end

After creating the above class, if I want the attributes which I have added in Lua(i.e. a1 and a2), I do the following:

obj = MyClass()

info = class_info(obj)
print("Methods:")
for k,v in pairs(info.methods) do 
    print(k .. ': ' .. tostring(v))
end

print("Attributes:")
for k,v in pairs(info.attributes) do 
    print(k .. ': ' .. tostring(v))
end

But I see only __init and no attributes. Is there a way to get the attributes a1 & a2?

I have stepped through get_class_info() while debugging (see https://github.com/luabind/luabind/blob/master/src/class_info.cpp#L33)

But that function does not seem to iterate more than once before exiting. Does anyone know the object format which is used by luabind? Or how I can extract these attributes?

Note: If I create a class in C++ and expose it through Luabind, then I do see any attributes that I exposed from C++. Its the attributes in Lua which are the issue.

0

There are 0 best solutions below