3 /* Purpose: Script interface */
12 * Execute a Python script
14 errr script_execute(char *name)
20 msg_print("Oops! No script given.");
24 /* Load a script file */
33 /* Either run the specified file or try to start "idle" */
36 /* Build the filename */
37 path_build(buf, 1024, ANGBAND_DIR_SCRIPT, name);
41 /* Build the filename */
42 path_build(buf, 1024, ANGBAND_DIR_SCRIPT, "idle.py");
45 fff = my_fopen(buf, "rw");
47 result = PyRun_SimpleFile(fff, buf);
55 return PyRun_SimpleString(name);
63 extern void initeventc(void);
64 extern void initplayerc(void);
65 extern void initioc(void);
66 extern void initobjectsc(void);
67 extern void initcavec(void);
68 extern void initmonsterc(void);
69 extern void initpclassc(void);
70 extern void initpracec(void);
71 extern void initterrainc(void);
72 extern void initcommandsc(void);
73 extern void initrealmsc(void);
74 extern void initrandomc(void);
75 extern void initspellsc(void);
76 extern void initstorec(void);
77 extern void initsystemc(void);
78 #endif /* STATIC_PYTHON */
82 * Initialize the script support
84 errr init_script(void)
89 cptr *program_name = &argv0;
91 Py_SetProgramName((char*)argv0);
94 /* Set the enviroment variables */
95 setenv("PYTHONPATH", ANGBAND_DIR_SCRIPT, 1);
96 setenv("PYTHONHOME", ANGBAND_DIR_SCRIPT, 1);
97 #endif /* __djgpp__ */
99 /* Initialize the Python interpreter */
102 /* Define sys.argv. It is up to the application if you
103 want this; you can also let it undefined (since the Python
104 code is generally not a main program it has no business
105 touching sys.argv...) */
106 PySys_SetArgv(1, (char **)program_name);
109 /* Convert the script path to a nice string */
110 ascii_to_text(path, ANGBAND_DIR_SCRIPT);
112 /* Build the path to the Python modules */
113 path_build(buf, 1024, ANGBAND_DIR_SCRIPT, "python");
115 /* Convert the script path to a nice string */
116 ascii_to_text(path1, buf);
118 /* Add the "script" directory to the module search path */
119 sprintf(buf, "import sys; sys.path.insert(0, '%s'); sys.path.insert(0, '%s')", path1, path);
121 if (PyRun_SimpleString(buf) == 0)
139 #endif /* STATIC_PYTHON */
141 if (PyRun_SimpleString("import init") == 0) return 0;
147 #endif /* USE_SCRIPT */