Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
666832fe
Commit
666832fe
authored
Dec 25, 1997
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Just for fun, add a static module, "xyzzy" -- show that calling its
initxyzzy() works.
parent
3ccaf0ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
Demo/embed/demo.c
Demo/embed/demo.c
+30
-0
No files found.
Demo/embed/demo.c
View file @
666832fe
...
...
@@ -4,6 +4,8 @@
static
char
*
argv0
;
void
initxyzzy
();
/* Forward */
main
(
argc
,
argv
)
int
argc
;
char
**
argv
;
...
...
@@ -14,6 +16,9 @@ main(argc, argv)
/* Initialize the Python interpreter. Required. */
Py_Initialize
();
/* Add a static module */
initxyzzy
();
/* 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
...
...
@@ -26,6 +31,7 @@ main(argc, argv)
/* Execute some Python statements (in module __main__) */
PyRun_SimpleString
(
"import sys
\n
"
);
PyRun_SimpleString
(
"print sys.builtin_module_names
\n
"
);
PyRun_SimpleString
(
"print sys.modules.keys()
\n
"
);
PyRun_SimpleString
(
"print sys.argv
\n
"
);
/* Note that you can call any public function of the Python
...
...
@@ -45,3 +51,27 @@ getprogramname()
{
return
argv0
;
}
/* A static module */
static
PyObject
*
xyzzy_foo
(
self
,
args
)
PyObject
*
self
;
/* Not used */
PyObject
*
args
;
{
if
(
!
PyArg_ParseTuple
(
args
,
""
))
return
NULL
;
return
PyInt_FromLong
(
42L
);
}
static
PyMethodDef
xyzzy_methods
[]
=
{
{
"foo"
,
xyzzy_foo
,
1
},
{
NULL
,
NULL
}
/* sentinel */
};
void
initxyzzy
()
{
PyImport_AddModule
(
"xyzzy"
);
Py_InitModule
(
"xyzzy"
,
xyzzy_methods
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment