Pass 'this' to a python script in an extended application

S

Stou Sandalski

Hi,

I have an application consisting of a main C++ class (and other
classes) stored inside a DLL. The application uses a small main
executable that links against the main DLL, then initializes and runs
the core class. The python bindings are inside a .pyd module that also
links against the core DLL file. I was able to generate the python
bindings against the core class using SWIG. The application can now
be run either by the bootstrap executable or through the python console
like:

import foo
s = foo.MainClass()
s.run();

This is awesome, however I want to be able to launch python scripts
from within the application itself (no matter how it was started) and
supply these scripts with a "pointer" to the already initialized main
Class something like:

import foo

s = foo.GetMainClass()
s.someMethod().

I found this:

http://docs.python.org/ext/extending-with-embedding.html

but the problem is that I don't know how to "give" the python
interpreter a "pointer" to my class that will be compatible with the
already defined bindings that SWIG generated. I am trying to keep the
core application dll from knowing about the .pyd extension module.

I apologize if this post belongs in a group dedicated to SWIG.

Stou
 
S

Stou Sandalski

I figured it out. I just made my main class a singleton and it worked
fine... it always works right after I post a message =)

Stou
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top