Swig bindings for python/lua do not initialize member data properly [closed]

◇◆丶佛笑我妖孽 提交于 2019-12-12 01:17:07

问题


I'm trying to build a set of Lua bindings for a collection of C++ classes, but have been toying with Python to see if I get better results. In either language the bindings seem to work, however, when I initialize an instance of a class that contains members of other classes, those data members do not seem to be guaranteed to be initialized.

For example, take the class:

class MyClass : public ParentClass // (Obviously) not a real class
{
    public:
        SomeClass sc;
        OtherClass oc;
};//Note that none of my classes have a constructor or destructor; this is by design.

When I generate bindings for a class like this, I am able to execute statements like:

var = module_name.MyClass()
print(var.sc.x, var.sc.y)

And I get the expected junk values printed to the screen. However, if I try to print anything about the instance of OtherClass, it becomes obvious that it is "stubbed out" -- in Lua it has no metatable at all and in Python doing dir(var.oc) gives only the default functions. However, if I then do:

var.oc = module_name.OtherClass()

The oc metatable / dir(oc) call are what I would have hoped for and it can be treated as expected.

Can anyone offer any insight into why only -some- of the member data are initialized?

Thanks!


回答1:


Turns out this problem was related to another problem I was having. See this thread for the resolution.



来源:https://stackoverflow.com/questions/916555/swig-bindings-for-python-lua-do-not-initialize-member-data-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!