diff options
| -rw-r--r-- | Mac/Demo/building.html | 2 | ||||
| -rw-r--r-- | Mac/Demo/embed.html | 36 | ||||
| -rw-r--r-- | Mac/Demo/embed/demo.c | 62 | ||||
| -rw-r--r-- | Mac/Demo/embed/embeddemo.mu.hqx | 174 | ||||
| -rw-r--r-- | Mac/Demo/index.html | 5 |
5 files changed, 278 insertions, 1 deletions
diff --git a/Mac/Demo/building.html b/Mac/Demo/building.html index 0afb35b..83e88e4 100644 --- a/Mac/Demo/building.html +++ b/Mac/Demo/building.html @@ -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> diff --git a/Mac/Demo/embed.html b/Mac/Demo/embed.html new file mode 100644 index 0000000..934619b --- /dev/null +++ b/Mac/Demo/embed.html @@ -0,0 +1,36 @@ +<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> diff --git a/Mac/Demo/embed/demo.c b/Mac/Demo/embed/demo.c new file mode 100644 index 0000000..a23c249 --- /dev/null +++ b/Mac/Demo/embed/demo.c @@ -0,0 +1,62 @@ +/* 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; +} diff --git a/Mac/Demo/embed/embeddemo.mu.hqx b/Mac/Demo/embed/embeddemo.mu.hqx new file mode 100644 index 0000000..b0de893 --- /dev/null +++ b/Mac/Demo/embed/embeddemo.mu.hqx @@ -0,0 +1,174 @@ +(This file must be converted with BinHex 4.0) + +:$'9YBQ9NC'9YEbjYG3"069"53eG*43#3""&i!!!Th4EVBfp[E!!!!!%!!!!F!!! +4$!!!%5J!!!"3!!!!"!!!!'J!!J!`!!)!(!4YB@PZ!$Nl!!(("!#3"MK!!*!&j1c +S!*!0!J!`!!)!+!PXD@*bBA*TCA-`b!#3"L!&!!)!N!F$!*!,!J!!!!)!+!PbCA0 +[GA*MCA-`b!#3"L!&!!-!N!F%!*!3@$`!N!`(4'9cDh4[F!$9k6!!N!B$N!!!eHd +J!,ii)!#q08J!!#R`!0ARB!#3%GATF!#3"J0J!0AY)&"jG'K[ELecD'&bC3$9jf! +!!`!!!X!!!`)S!!!!23!"!*!)!J%!N!3'C'9YEbjM!*!L!`#3"c#Y(r*!!!%!2+` +KJ-!!!3!jV#'!`!!"!!UY2klb!!%!1UdImN!!!3!eV4rb3!!"!$'X)B$!!!%!0+` +KJ-!!!3!lV#'!`!!"!$+Y8ec!!!%!-kfce6X!!3!fV')D3!!"!$HX)B$!!!%!2ke +Nl!B!!3!iV#'!`!!"!#@Y2kqp!!%!"kdrV[3!!3!,V6qZp!!"!!QY2kld!!%!2U` +KJ-!!!3