diff options
author | Guido van Rossum <guido@python.org> | 1994-10-08 19:30:50 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1994-10-08 19:30:50 (GMT) |
commit | 705d517e3f4df74b8c04edf54ac73b087c982f32 (patch) | |
tree | 7b0543f1165fc1bdfc4717277f67d8e699dcbeb4 /Demo/embed/demo.c | |
parent | 3dc44aba71305cd9be8cba7703a96b6528f34169 (diff) | |
download | cpython-705d517e3f4df74b8c04edf54ac73b087c982f32.zip cpython-705d517e3f4df74b8c04edf54ac73b087c982f32.tar.gz cpython-705d517e3f4df74b8c04edf54ac73b087c982f32.tar.bz2 |
initial checkin
Diffstat (limited to 'Demo/embed/demo.c')
-rw-r--r-- | Demo/embed/demo.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Demo/embed/demo.c b/Demo/embed/demo.c new file mode 100644 index 0000000..b1adde2 --- /dev/null +++ b/Demo/embed/demo.c @@ -0,0 +1,46 @@ +/* Example of embedding Python in another program */ + +#include "allobjects.h" + +static char *argv0; + +main(argc, argv) + int argc; + char **argv; +{ + /* Save a copy of argv0 */ + argv0 = argv[0]; + + /* Initialize the Python interpreter. Required. */ + initall(); + + /* Define sys.argv. It is up to the application if you + want this; you can also let it undefined (since the Python + code is generally not a main program it has no business + touching sys.argv...) */ + setpythonargv(argc, argv); + + /* Do some application specific code */ + printf("Hello, brave new world\n\n"); + + /* Execute some Python statements (in module __main__) */ + run_command("import sys\n"); + run_command("print sys.builtin_module_names\n"); + run_command("print sys.argv\n"); + + /* Note that you can call any public function of the Python + interpreter here, e.g. call_object(). */ + + /* Some more application specific code */ + printf("\nGoodbye, cruel world\n"); + + /* Exit, cleaning up the interpreter */ + goaway(0); + /*NOTREACHED*/ +} + +char * +getprogramname() +{ + return argv0; +} |