Commit 6ad8d13f authored by Jack Jansen's avatar Jack Jansen

"ported" Guido's embedding demo to the mac, and wrote some minimal

notes on embedding on the mac.
parent 52ac0372
......@@ -482,6 +482,6 @@ be able to obtain resources from the library file lateron. Plugins can do the sa
use the standard <code>__initialize</code> entry point.
<UL>
</UL>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>Embedding Python on the Mac</TITLE>
</HEAD>
<BODY>
<H1>Embedding Python on the Mac</H1>
<HR>
Embedding Python on the mac is pretty similar to embedding it on other
platforms, but a few points need mentioning:
<UL>
<LI> You call <CODE>PyMac_Initialize()</CODE> in stead of
<CODE>Py_Initialize()</CODE>. The prototype is in <CODE>macglue.h</CODE>.
This call initializes the toolbox, GUSI (if needed), sets up the correct
resource files and calls Py_Initialize.
<LI> You have to be consequent in your use of GUSI. If the library uses
it so should your program and vice versa.
<LI> The console-behaviour (close-on-exit, etc) is controlled by Python,
but you are of course free to change that after calling PyMac_Initialize().
</UL>
The Python environment is started with a dummy argc and argv, and initial
startup options are obtained through the usual means, except that the
user pression the option-key will not result in an interactive dialog.
You can, however, set startup options on your program in the same way as you
do for applets, by dragging your application to <code>EditPythonPrefs</code>. <p>
The most logical way to embed Python is to link it against the shared library
<code>PythonCorePPC</code> or <code>PythonCoreCFM68K</code>. An example project
and source can be found in the <a href="embed">embed</a> folder.
</BODY>
</HTML>
/* Example of embedding Python in another program */
#include "Python.h"
#ifdef macintosh
#include "macglue.h"
#include <SIOUX.h>
#endif /* macintosh */
static char *argv0;
main(argc, argv)
int argc;
char **argv;
{
#ifdef macintosh
/* So the user can set argc/argv to something interesting */
argc = ccommand(&argv);
#endif
/* Save a copy of argv0 */
argv0 = argv[0];
/* Initialize the Python interpreter. Required. */
#ifdef macintosh
PyMac_Initialize();
#else
Py_Initialize();
#endif
/* 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...) */
PySys_SetArgv(argc, argv);
/* Do some application specific code */
printf("Hello, brave new world\n\n");
/* Execute some Python statements (in module __main__) */
PyRun_SimpleString("import sys\n");
PyRun_SimpleString("print sys.builtin_module_names\n");
PyRun_SimpleString("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");
#ifdef macintosh
printf("Type return or so-\n");
getchar();
#endif
/* Exit, cleaning up the interpreter */
Py_Exit(0);
/*NOTREACHED*/
}
/* This function is called by the interpreter to get its own name */
char *
getprogramname()
{
return argv0;
}
This diff is collapsed.
......@@ -89,6 +89,11 @@ in Python.
<LI>
<A HREF="building.html">Building Mac Python from source</A> explains
how to build a PPC or 68K interpreter from a source distribution.
<LI>
<A HREF="embed.html">Embedding Python on the Mac</A> is a minimal example of
how to embed Python in other Mac applications.
</UL>
The Python distribution contains a few more examples, all unexplained:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment