Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3caad8c

Browse files
committed
adapted to new naming; clarify comments somewhat
1 parent 1b91cda commit 3caad8c

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

Demo/embed/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ INCLUDES= -I$(srcdir)/Include -I$(blddir)
1010
DEFINES= -DHAVE_CONFIG_H
1111
CFLAGS= $(OPT) $(DEFINES) $(INCLUDES)
1212

13-
# Libraries
14-
# XXX edit MODLIBS, LIBS and SYSLIBS to match $(blddir)/Modules/Makefile
13+
# Libraries (must be in this order!)
1514
MYLIBS= $(blddir)/Modules/libModules.a \
1615
$(blddir)/Python/libPython.a \
1716
$(blddir)/Objects/libObjects.a \
1817
$(blddir)/Parser/libParser.a
18+
19+
# XXX edit MODLIBS, LIBS and SYSLIBS to match $(blddir)/Modules/Makefile
1920
MODLIBS=
2021
LIBS=
2122
SYSLIBS= -lm

Demo/embed/README

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
This directory show how easy it is to embed the Python interpreter in
2-
your own application. The file demo.c shows you all that is needed in
3-
your C code.
1+
This directory show how to embed the Python interpreter in your own
2+
application. The file demo.c shows you all that is needed in your C
3+
code.
44

55
To build it, you may have to edit the Makefile:
66

Demo/embed/demo.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Example of embedding Python in another program */
22

3-
#include "allobjects.h"
3+
#include "Python.h"
44

55
static char *argv0;
66

@@ -12,21 +12,21 @@ main(argc, argv)
1212
argv0 = argv[0];
1313

1414
/* Initialize the Python interpreter. Required. */
15-
initall();
15+
Py_Initialize();
1616

1717
/* Define sys.argv. It is up to the application if you
1818
want this; you can also let it undefined (since the Python
1919
code is generally not a main program it has no business
2020
touching sys.argv...) */
21-
setpythonargv(argc, argv);
21+
PySys_SetArgv(argc, argv);
2222

2323
/* Do some application specific code */
2424
printf("Hello, brave new world\n\n");
2525

2626
/* Execute some Python statements (in module __main__) */
27-
run_command("import sys\n");
28-
run_command("print sys.builtin_module_names\n");
29-
run_command("print sys.argv\n");
27+
PyRun_SimpleString("import sys\n");
28+
PyRun_SimpleString("print sys.builtin_module_names\n");
29+
PyRun_SimpleString("print sys.argv\n");
3030

3131
/* Note that you can call any public function of the Python
3232
interpreter here, e.g. call_object(). */
@@ -35,10 +35,11 @@ main(argc, argv)
3535
printf("\nGoodbye, cruel world\n");
3636

3737
/* Exit, cleaning up the interpreter */
38-
goaway(0);
38+
Py_Exit(0);
3939
/*NOTREACHED*/
4040
}
4141

42+
/* This function is called by the interpreter to get its own name */
4243
char *
4344
getprogramname()
4445
{

0 commit comments

Comments
 (0)