471,873 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

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 1242
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 YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.