swig 包装变量的基本分配失败 [英] Basic assignment of swig wrapped variables fails

查看:26
本文介绍了swig 包装变量的基本分配失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 swig 创建了一个包含大量 C++ 类的 lua 模块.包装器的生成和编译(使用 -Wall)没有任何问题.但是,在我发现的几个地方,我遇到了以下问题:成员数据的基本分配失败.

I created a lua module with a very large number of wrapped C++ classes using swig. The wrappers are generated and compiled (with -Wall) without any issues. However, in a couple of places that I've found, I run into the following issue: basic assignment of member data fails.

如果我跑:

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require('myModule')
> a = myModule.ClassA()

然后我可以验证附加到a"的元表是否包含其所有成员数据(在本例中,字段b"和c"分别属于类类型 ClassB 和 ClassC.)

I can then verify that the metatable attached to "a" contains all of its member data (in this case fields "b" and "c", of class type ClassB and ClassC respectively.)

我还可以:

> a.b = myModule.ClassB()

成功地将 b 重新分配给 ClassB() 的新实例.但是,当我去做:

which reassigns b to a new instance of ClassB() successfully. However, when I go to do:

> a.b.c = myModule.ClassC()

我收到错误消息:

Error in ClassB_c_set (arg 2), expected 'ClassC *' got 'ClassB *'

好像="右侧的表达式是与包含要重新分配的数据字段的元素具有相同类型的对象.我确定我一定遗漏了一些简单的东西,但我已经用头撞墙几个小时了,但无济于事.

As though the expression on the right side of the '=' was an object of the same type as the element containing the data field to be reassigned. I'm sure I must be missing something simple, but I've been banging my head against the wall for a few hours now to no avail.

有人有什么想法吗?谢谢!

Anybody have any thoughts? Thanks!

推荐答案

事实证明这是 SWIG 中的一个错误.我已经提交了 一个错误报告,解释了原因问题.

It turns out that this is a bug in SWIG. I've submitted a bug report explaining the cause of the problem.

这个问题实际上是由于嵌套命名空间问题以及我对 SWIG 如何工作的误解造成的.我假设我通过接口文件中的 %include 引入的每个项目都将按照 gcc 处理 #includes 的方式进行处理.但是,在 SWIG 文件中,必须按照其内容被引用的顺序进行 %include.

This problem was actually due to a nested namespace issue combined with a misunderstanding of how SWIG works on my part. I had assumed that each item I brought in via %include in my interface file would be processed the way that gcc processes #includes. However, in SWIG files must be %included in the order their contents are referenced.

请参阅链接的错误报告以进行说明.

See the linked bug report for clarification.

这篇关于swig 包装变量的基本分配失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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