supply more information about errors when running scripts

This commit is contained in:
Dana Jansens 2003-02-16 18:16:55 +00:00
parent 16a952c35d
commit 93ea4c4d2e
2 changed files with 5 additions and 4 deletions

View file

@ -35,12 +35,12 @@ void python_destroy()
Py_Finalize(); Py_Finalize();
} }
bool python_exec(const std::string &path) int python_exec(const std::string &path)
{ {
FILE *rcpyfd = fopen(path.c_str(), "r"); FILE *rcpyfd = fopen(path.c_str(), "r");
if (!rcpyfd) { if (!rcpyfd) {
fprintf(stderr, _("Unabled to open python file %s\n"), path.c_str()); fprintf(stderr, _("Unabled to open python file %s\n"), path.c_str());
return false; return 1;
} }
//PyRun_SimpleFile(rcpyfd, const_cast<char*>(path.c_str())); //PyRun_SimpleFile(rcpyfd, const_cast<char*>(path.c_str()));
@ -51,7 +51,7 @@ bool python_exec(const std::string &path)
assert(dict); assert(dict);
PyObject *result = PyRun_File(rcpyfd, const_cast<char*>(path.c_str()), PyObject *result = PyRun_File(rcpyfd, const_cast<char*>(path.c_str()),
Py_file_input, dict, dict); Py_file_input, dict, dict);
bool ret = result != NULL; int ret = result == NULL ? 2 : 0;
if (result == NULL) if (result == NULL)
PyErr_Print(); PyErr_Print();

View file

@ -231,7 +231,8 @@ typedef void (*EventCallback)(EventData*, void*);
void python_init(char *argv0); void python_init(char *argv0);
void python_destroy(); void python_destroy();
bool python_exec(const std::string &path); //! Returns 0 for success, 1 for failing to open the file, 2 for an exception
int python_exec(const std::string &path);
#endif // SWIG #endif // SWIG