469,338 Members | 8,430 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,338 developers. It's quick & easy.

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

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

Jan 19 '07 #1
1 1188
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

Stou Sandalski wrote:
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...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
Jan 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

IDE
49 posts views Thread by Thomas Lindgaard | last post: by
9 posts views Thread by Martin Drautzburg | last post: by
reply views Thread by John Pote | last post: by
9 posts views Thread by runes | last post: by
12 posts views Thread by BartlebyScrivener | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
18 posts views Thread by Jens | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.