views:

90

answers:

1

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.

If I run:

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

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

I can further do:

> a.b = myModule.ClassB()

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

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

I receive the error message:

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!

+1  A: 

It turns out that this is a bug in SWIG. I've submitted a bug report explaining the cause of the problem. Now I play the waiting game. :P

EDIT --

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 above link for clarification.

Zack