@@ -121,9 +121,9 @@ void FUnrealEnginePythonModule::UESetupPythonInterpreter(bool verbose)
121121
122122 for (int32 i = 0 ; i < Args.Num (); i++)
123123 {
124- #if PY_MAJOR_VERSION >= 3
125- argv[i] = (wchar_t *)(*Args[i]);
126- #if ENGINE_MINOR_VERSION >= 20
124+ #if PY_MAJOR_VERSION >= 3
125+ argv[i] = (wchar_t *)(*Args[i]);
126+ #if ENGINE_MINOR_VERSION >= 20
127127 argv[i] = (wchar_t *)(TCHAR_TO_WCHAR (*Args[i]));
128128 #else
129129 argv[i] = (wchar_t *)(*Args[i]);
@@ -550,22 +550,35 @@ void FUnrealEnginePythonModule::ShutdownModule()
550550 }
551551}
552552
553- void FUnrealEnginePythonModule::RunString (char *str)
553+ FString FUnrealEnginePythonModule::RunString (char *str)
554554{
555555 FScopePythonGIL gil;
556556
557- PyObject *eval_ret = PyRun_String (str, Py_file_input , (PyObject *)main_dict, (PyObject *)local_dict);
557+ PyObject *eval_ret = PyRun_String (str, Py_single_input , (PyObject *)main_dict, (PyObject *)local_dict);
558558 if (!eval_ret)
559559 {
560560 if (PyErr_ExceptionMatches (PyExc_SystemExit))
561561 {
562562 PyErr_Clear ();
563- return ;
563+ return " " ;
564564 }
565565 unreal_engine_py_log_error ();
566- return ;
566+ return " " ;
567+ }
568+
569+ FString ue4_str_ret;
570+ if (eval_ret != Py_None)
571+ {
572+ PyObject *stringified = PyObject_Str (eval_ret);
573+ if (!stringified)
574+ return " argument cannot be casted to string" ;
575+
576+ ue4_str_ret = UTF8_TO_TCHAR (UEPyUnicode_AsUTF8 (stringified));
567577 }
578+
568579 Py_DECREF (eval_ret);
580+
581+ return ue4_str_ret;
569582}
570583
571584#if PLATFORM_MAC
@@ -629,7 +642,7 @@ FString FUnrealEnginePythonModule::Pep8ize(FString Code)
629642}
630643
631644
632- void FUnrealEnginePythonModule::RunFile (char *filename)
645+ FString FUnrealEnginePythonModule::RunFile (char *filename)
633646{
634647 FScopePythonGIL gil;
635648 FString full_path = UTF8_TO_TCHAR (filename);
@@ -655,7 +668,7 @@ void FUnrealEnginePythonModule::RunFile(char *filename)
655668 if (!foundFile)
656669 {
657670 UE_LOG (LogPython, Error, TEXT (" Unable to find file %s" ), UTF8_TO_TCHAR (filename));
658- return ;
671+ return " " ;
659672 }
660673
661674#if PY_MAJOR_VERSION >= 3
@@ -665,14 +678,14 @@ void FUnrealEnginePythonModule::RunFile(char *filename)
665678 if (fopen_s (&fd, TCHAR_TO_UTF8 (*full_path), " r" ) != 0 )
666679 {
667680 UE_LOG (LogPython, Error, TEXT (" Unable to open file %s" ), *full_path);
668- return ;
681+ return " " ;
669682 }
670683#else
671684 fd = fopen (TCHAR_TO_UTF8 (*full_path), " r" );
672685 if (!fd)
673686 {
674687 UE_LOG (LogPython, Error, TEXT (" Unable to open file %s" ), *full_path);
675- return ;
688+ return " " ;
676689 }
677690#endif
678691
@@ -683,12 +696,20 @@ void FUnrealEnginePythonModule::RunFile(char *filename)
683696 if (PyErr_ExceptionMatches (PyExc_SystemExit))
684697 {
685698 PyErr_Clear ();
686- return ;
699+ return " " ;
687700 }
688701 unreal_engine_py_log_error ();
689- return ;
702+ return " " ;
690703 }
704+
705+ PyObject *stringified = PyObject_Str (eval_ret);
706+ if (!stringified)
707+ return " argument cannot be casted to string" ;
708+
709+ FString ue4_string = UTF8_TO_TCHAR (UEPyUnicode_AsUTF8 (stringified));
691710 Py_DECREF (eval_ret);
711+
712+ return ue4_string;
692713#else
693714 // damn, this is horrible, but it is the only way i found to avoid the CRT error :(
694715 FString command = FString::Printf (TEXT (" execfile(\" %s\" )" ), *full_path);
@@ -701,8 +722,15 @@ void FUnrealEnginePythonModule::RunFile(char *filename)
701722 return ;
702723 }
703724 unreal_engine_py_log_error ();
704- return ;
725+ return " " ;
705726 }
727+
728+ PyObject *stringified = PyObject_Str (eval_ret);
729+ if (!stringified)
730+ return " argument cannot be casted to string" ;
731+
732+ FString ue4_string = UTF8_TO_TCHAR (UEPyUnicode_AsUTF8 (stringified));
733+ return ue4_string;
706734#endif
707735
708736}
0 commit comments