@@ -121,9 +121,9 @@ void FUnrealEnginePythonModule::UESetupPythonInterpreter(bool verbose)
121
121
122
122
for (int32 i = 0 ; i < Args.Num (); i++)
123
123
{
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
127
127
argv[i] = (wchar_t *)(TCHAR_TO_WCHAR (*Args[i]));
128
128
#else
129
129
argv[i] = (wchar_t *)(*Args[i]);
@@ -550,22 +550,35 @@ void FUnrealEnginePythonModule::ShutdownModule()
550
550
}
551
551
}
552
552
553
- void FUnrealEnginePythonModule::RunString (char *str)
553
+ FString FUnrealEnginePythonModule::RunString (char *str)
554
554
{
555
555
FScopePythonGIL gil;
556
556
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);
558
558
if (!eval_ret)
559
559
{
560
560
if (PyErr_ExceptionMatches (PyExc_SystemExit))
561
561
{
562
562
PyErr_Clear ();
563
- return ;
563
+ return " " ;
564
564
}
565
565
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));
567
577
}
578
+
568
579
Py_DECREF (eval_ret);
580
+
581
+ return ue4_str_ret;
569
582
}
570
583
571
584
#if PLATFORM_MAC
@@ -629,7 +642,7 @@ FString FUnrealEnginePythonModule::Pep8ize(FString Code)
629
642
}
630
643
631
644
632
- void FUnrealEnginePythonModule::RunFile (char *filename)
645
+ FString FUnrealEnginePythonModule::RunFile (char *filename)
633
646
{
634
647
FScopePythonGIL gil;
635
648
FString full_path = UTF8_TO_TCHAR (filename);
@@ -655,7 +668,7 @@ void FUnrealEnginePythonModule::RunFile(char *filename)
655
668
if (!foundFile)
656
669
{
657
670
UE_LOG (LogPython, Error, TEXT (" Unable to find file %s" ), UTF8_TO_TCHAR (filename));
658
- return ;
671
+ return " " ;
659
672
}
660
673
661
674
#if PY_MAJOR_VERSION >= 3
@@ -665,14 +678,14 @@ void FUnrealEnginePythonModule::RunFile(char *filename)
665
678
if (fopen_s (&fd, TCHAR_TO_UTF8 (*full_path), " r" ) != 0 )
666
679
{
667
680
UE_LOG (LogPython, Error, TEXT (" Unable to open file %s" ), *full_path);
668
- return ;
681
+ return " " ;
669
682
}
670
683
#else
671
684
fd = fopen (TCHAR_TO_UTF8 (*full_path), " r" );
672
685
if (!fd)
673
686
{
674
687
UE_LOG (LogPython, Error, TEXT (" Unable to open file %s" ), *full_path);
675
- return ;
688
+ return " " ;
676
689
}
677
690
#endif
678
691
@@ -683,12 +696,20 @@ void FUnrealEnginePythonModule::RunFile(char *filename)
683
696
if (PyErr_ExceptionMatches (PyExc_SystemExit))
684
697
{
685
698
PyErr_Clear ();
686
- return ;
699
+ return " " ;
687
700
}
688
701
unreal_engine_py_log_error ();
689
- return ;
702
+ return " " ;
690
703
}
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));
691
710
Py_DECREF (eval_ret);
711
+
712
+ return ue4_string;
692
713
#else
693
714
// damn, this is horrible, but it is the only way i found to avoid the CRT error :(
694
715
FString command = FString::Printf (TEXT (" execfile(\" %s\" )" ), *full_path);
@@ -701,8 +722,15 @@ void FUnrealEnginePythonModule::RunFile(char *filename)
701
722
return ;
702
723
}
703
724
unreal_engine_py_log_error ();
704
- return ;
725
+ return " " ;
705
726
}
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;
706
734
#endif
707
735
708
736
}
0 commit comments