11
22#include " PythonScript.h"
33
4- static void callback (void *arg) {
4+ #include " UEPyModule.h"
5+
6+
7+ static void callback (void *arg)
8+ {
59 UPythonScript *self = (UPythonScript *)arg;
610 self->CallSpecificFunctionWithArgs ();
711}
812
9- void UPythonScript::Run () {
13+ void UPythonScript::Run ()
14+ {
1015 FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>(" UnrealEnginePython" );
1116 PythonModule.RunFile (TCHAR_TO_UTF8 (*ScriptPath));
12- if (!FunctionToCall.IsEmpty ()) {
17+ if (!FunctionToCall.IsEmpty ())
18+ {
1319 CallSpecificFunctionWithArgs ();
1420 }
1521}
1622
17- void UPythonScript::RunSandboxed () {
23+ void UPythonScript::RunSandboxed ()
24+ {
1825 FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>(" UnrealEnginePython" );
1926 PythonModule.RunFileSandboxed (TCHAR_TO_UTF8 (*ScriptPath), callback, this );
2027}
2128
22- void UPythonScript::CallSpecificFunctionWithArgs () {
29+ void UPythonScript::CallSpecificFunctionWithArgs ()
30+ {
2331 PyObject *function_to_call = PyDict_GetItemString (PyEval_GetGlobals (), TCHAR_TO_UTF8 (*FunctionToCall));
24- if (!function_to_call) {
32+ if (!function_to_call)
33+ {
2534 UE_LOG (LogPython, Error, TEXT (" unable to find function %s" ), *FunctionToCall);
2635 return ;
2736 }
@@ -32,16 +41,19 @@ void UPythonScript::CallSpecificFunctionWithArgs() {
3241 if (n > 0 )
3342 args = PyTuple_New (n);
3443
35- for (int i = 0 ; i < n; i++) {
44+ for (int i = 0 ; i < n; i++)
45+ {
3646 PyTuple_SetItem (args, i, PyUnicode_FromString (TCHAR_TO_UTF8 (*FunctionArgs[i])));
3747 }
3848
3949 PyObject *ret = PyObject_Call (function_to_call, args, nullptr );
4050 Py_DECREF (args);
41- if (!ret) {
51+ if (!ret)
52+ {
4253 unreal_engine_py_log_error ();
4354 }
44- else {
55+ else
56+ {
4557 Py_DECREF (ret);
4658 }
4759}
0 commit comments