python as plugin language

Lyle Johnson ljohnson at resgen.com
Tue Jun 26 10:08:31 EDT 2001


> could someone please enlighten me! I want to embed python in my app
> as a scripting language... I have succeeded in extending python via swig.
> Not what I want, because main() has to come from my c-app.
>
> Then i can embed python in a c program with things #include "Python.h"
> and Py_Initialize(), etc. but that is still not what i want, because i
have no
> idea how I can call C-Funktions with this approach... clear what i mean?
> I fear not...
>
> From my app I want to load a plugin (a python script) and from this script
> I want to access functions of my app.
>
> Some pointers would be _very_ welcome!!

If you've already learned how to develop C extension modules (using SWIG, or
"by hand") you've gotten past the biggest hurdle. And it sounds like you've
got the idea w. r. t. embedding Python in your application. I know of two
books that do a pretty good job of explaining the "big picture" for
embedding Python as an application-scripting language. One is "Programming
Python", by Mark Lutz; the other is "Internet Programming with Python", by
Aaron Watters, Guido van Rossum and James C. Ahlstrom. The latter may be out
of print, but if you run across it you'll probably be able to get it for
cheap. A good general approach, though, is:

 1. Develop one or more C extension modules that expose some subset of your
application's functionality,
     i.e. the stuff you'd like to be able to access from a Python script.

 2. Embed the Python interpreter in your application, initialize it by
calling Py_Initialize(), etc.

 3. At some selected point(s) during your application's execution, pass the
user's "plugin" script
    to the embedded Python interpreter. Within that script, the user will
presumably import your
    extension module(s) and make application-specific calls back into your
application.

Hope this helps,

Lyle





More information about the Python-list mailing list