Help with SWIG

Ok - it compiles now!

I tried testing my new class in Panda, and I received this:


DirectStart: Starting the game.
Warning: DirectNotify: category 'Interval' already exists
Known pipe types:
  wglGraphicsPipe
(3 aux display modules not yet loaded.)
Traceback (most recent call last):
  File "CPP_Test_1.py", line 15, in ?
    result1 = pt.InitDevice()
AttributeError: PandaTest instance has no attribute 'InitDevice'

This is my test class:


import direct.directbase.DirectStart
from pandac.PandaModules import PandaTest

pt = PandaTest()
result1 = pt.InitDevice()
result2 = pt.Method1()
result3 = pt.Method2("test")
print "InitDevice result: %d"%(result1)
print "Method1 result: %d"%(result2)
print "Method2 result: %d"%(result3)

Am I trying to call these methods incorrectly, or is something else wrong? It’s not balking on the call to the constructor, though… This is also the format I used to test my first class (the simple adder). Thanks again for the help - I think we’re almost there!

-Ogel

Not sure on this one. But I do know that interrogate does method-name translation:

C++ method “foo_bar” -> python method “fooBar”

I wonder if the translation is causing problems? Try this… rename the C++ method to “init_device” and then call it from python as “initDevice”, and see what happens.

Hm… I believe there’s a tool in python to say “show me all the methods of this object.” I can’t remember how to use that tool, but it bears investigation.

Ok - I think it’s working now! The last error was my fault - my PATH env variable was still pointing at Panda 1.0.4. I was using it before you mentioned the “AddToVisualStudioPath” stuff (which isn’t in 1.0.4), and when I switched I didn’t update the PATH. So it was looking at my old ‘PandaTest’ class.

Once I fixed that, I still had a few new errors to work around. I was apparently using BEGIN_PUBLISH incorrectly. This is what I had:

private:
    ....

public:
BEGIN_PUBLISH
    PandaTest()
    void Method1()
    ....
END_PUBLISH

I guess that’s wrong - maybe I should have removed the ‘public:’ right before? Anyway, I just switched ‘public:’ with ‘PUBLISHED:’ (as in most of the other .h files) and it’s working.

I also had to add some ‘const’ modifiers to my code. The Python wrappers added ‘const’ to a number of the char* method parameters. I guess this is normal, right? If you have any other suggestions for using C++ with Python (e.g. “don’t ever send pass in this type of data”, etc.), please let me know.

Anyway, thanks again for all of your help. This will help our prototyping efforts a great deal! :smiley: