/** @param persist: If true, retain the Python interpreter, else finalize it @param code: The multiline string of Python code. The last line is evaluated to the returned result @param output: Store result pointer here @return Tcl error code */ static int python_eval(bool persist, const char* code, const char* expression, Tcl_Obj** output) { int rc; char* result = python_result_default; // Initialize: rc = python_init(); TCL_CHECK(rc); // Execute code: DEBUG_TCL_TURBINE("python: code: %s", code); PyObject* localDictionary = PyDict_New(); PyRun_String(code, Py_file_input, main_dict, localDictionary); if (PyErr_Occurred()) return handle_python_exception(); // Evaluate expression: DEBUG_TCL_TURBINE("python: expression: %s", expression); PyObject* o = PyRun_String(expression, Py_eval_input, main_dict, localDictionary); if (o == NULL) return handle_python_exception(); // Convert Python result to C string, then to Tcl string: rc = PyArg_Parse(o, "s", &result); if (rc != 1) return handle_python_non_string(o); DEBUG_TCL_TURBINE("python: result: %s\n", result); *output = Tcl_NewStringObj(result, -1); // Clean up and return: Py_DECREF(o); if (!persist) python_finalize(); return TCL_OK; }
int main (int argc, char **argv) { signal (SIGSEGV, sig_segv_handler); signal (SIGABRT, sig_abrt_handler); log_level = 10; args_parse (argc, argv); printf ( "Telegram-client version " TG_VERSION ", Copyright (C) 2013 Vitaly Valtman\n" "Telegram-client comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n" "This is free software, and you are welcome to redistribute it\n" "under certain conditions; type `show_license' for details.\n" ); running_for_first_time (); parse_config (); get_terminal_attributes (); #ifdef USE_LUA if (lua_file) { lua_init (lua_file); } #endif #ifdef USE_PYTHON if (python_file) { python_init(python_file); } #endif inner_main (); #ifdef USE_PYTHON if (python_file) { python_finalize(); } #endif return 0; }