@@ -128,9 +128,7 @@ SPythonConsoleInputBox::SPythonConsoleInputBox()
128128 : bIgnoreUIUpdate(false )
129129{
130130 FScopePythonGIL gil;
131- PyObject *main_module = PyImport_AddModule (" __main__" );
132- main_dict = PyModule_GetDict (main_module);
133- local_dict = PyDict_New ();
131+
134132}
135133
136134BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
@@ -181,82 +179,10 @@ void SPythonConsoleInputBox::OnTextCommitted(const FText& InText, ETextCommit::T
181179
182180 // Here run the python code
183181 //
184- FScopePythonGIL gil;
182+ FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>(" UnrealEnginePython" );
183+ PythonModule.RunString (TCHAR_TO_UTF8 (*ExecString));
185184
186- PyObject *eval_ret = PyRun_String (TCHAR_TO_UTF8 (*ExecString), Py_file_input, main_dict, local_dict);
187-
188- if (eval_ret) {
189- Py_DECREF (eval_ret);
190- }
191-
192-
193- if (PyErr_Occurred ()) {
194- PyObject *type = NULL ;
195- PyObject *value = NULL ;
196- PyObject *traceback = NULL ;
197-
198- PyErr_Fetch (&type, &value, &traceback);
199- PyErr_NormalizeException (&type, &value, &traceback);
200-
201- if (!value) {
202- PyErr_Clear ();
203- OnConsoleCommandExecuted.ExecuteIfBound ();
204- return ;
205- }
206-
207- char *msg = NULL ;
208- PyObject *zero = PyUnicode_AsUTF8String (PyObject_Str (value));
209- if (zero) {
210- msg = PyBytes_AsString (zero);
211- }
212-
213- if (!msg) {
214- PyErr_Clear ();
215- OnConsoleCommandExecuted.ExecuteIfBound ();
216- return ;
217- }
218-
219- UE_LOG (LogTemp, Error, TEXT (" %s" ), UTF8_TO_TCHAR (msg));
220-
221- // taken from uWSGI ;)
222- if (!traceback) {
223- PyErr_Clear ();
224- OnConsoleCommandExecuted.ExecuteIfBound ();
225- return ;
226- }
227-
228- PyObject *traceback_module = PyImport_ImportModule (" traceback" );
229- if (!traceback_module) {
230- PyErr_Clear ();
231- OnConsoleCommandExecuted.ExecuteIfBound ();
232- return ;
233- }
234-
235- PyObject *traceback_dict = PyModule_GetDict (traceback_module);
236- PyObject *format_exception = PyDict_GetItemString (traceback_dict, " format_exception" );
237-
238- if (format_exception) {
239- PyObject *ret = PyObject_CallFunctionObjArgs (format_exception, type, value, traceback, NULL );
240- if (!ret) {
241- PyErr_Clear ();
242- OnConsoleCommandExecuted.ExecuteIfBound ();
243- return ;
244- }
245-
246- if (PyList_Check (ret)) {
247- for (int i = 0 ; i < PyList_Size (ret); i++) {
248- PyObject *item = PyList_GetItem (ret, i);
249- if (item) {
250- UE_LOG (LogTemp, Error, TEXT (" %s" ), UTF8_TO_TCHAR (PyUnicode_AsUTF8 (PyObject_Str (item))));
251- }
252- }
253- }
254- else {
255- UE_LOG (LogTemp, Error, TEXT (" %s" ), UTF8_TO_TCHAR (PyUnicode_AsUTF8 (PyObject_Str (ret))));
256- }
257- }
258- PyErr_Clear ();
259- }
185+
260186 }
261187
262188 }
0 commit comments