python/lua的Swig绑定无法正确初始化成员数据 [英] Swig bindings for python/lua do not initialize member data properly

查看:89
本文介绍了python/lua的Swig绑定无法正确初始化成员数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为一组C ++类构建一套Lua绑定,但是一直在玩弄Python以查看是否获得了更好的结果.在这两种语言中,绑定似乎都起作用,但是,当我初始化包含其他类的成员的类的实例时,似乎不能保证这些数据成员被初始化.

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.

例如,上课:

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)

然后我将预期的垃圾值打印到屏幕上.但是,如果我尝试打印有关OtherClass实例的任何内容,很明显它是存根"的-在Lua中它根本没有元表,而在Python中,dir(var.oc)仅提供默认函数.但是,如果我这样做:

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()

oc metatable/dir(oc)调用是我所希望的,并且可以按预期对待.

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?

谢谢!

推荐答案

原来,这个问题与我遇到的另一个问题有关.有关解决方法,请参见此线程.

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

这篇关于python/lua的Swig绑定无法正确初始化成员数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆