Skip to content

Commit e059aa4

Browse files
committed
python 2 is now supported on mac too
1 parent 9b4e034 commit e059aa4

File tree

7 files changed

+47
-44
lines changed

7 files changed

+47
-44
lines changed

Source/UnrealEnginePython/Private/UnrealEnginePythonPrivatePCH.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
#endif
1515

1616

17-
#if UNREAL_ENGINE_PYTHON_ON_MAC
17+
#if UNREAL_ENGINE_PYTHON_ON_MAC == 3
1818
#include <python3.5m/Python.h>
19+
#elif UNREAL_ENGINE_PYTHON_ON_MAC == 2
20+
#include <python2.7/Python.h>
1921
#else
2022
#include <include/Python.h>
2123
#endif
@@ -38,4 +40,4 @@
3840

3941
#if PY_MAJOR_VERSION < 3
4042
char *PyUnicode_AsUTF8(PyObject *py_str);
41-
#endif
43+
#endif

Source/UnrealEnginePython/Public/PyActor.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,26 @@ void APyActor::BeginPlay()
6363
py_uobject = ue_get_python_wrapper(this);
6464

6565
if (py_uobject) {
66-
PyObject_SetAttrString(py_actor_instance, "uobject", (PyObject *)py_uobject);
66+
PyObject_SetAttrString(py_actor_instance, (char*)"uobject", (PyObject *)py_uobject);
6767
}
6868
else {
6969
UE_LOG(LogPython, Error, TEXT("Unable to set 'uobject' field in actor wrapper class"));
7070
unreal_engine_py_log_error();
7171
return;
7272
}
7373

74-
if (!PyObject_HasAttrString(py_actor_instance, "tick") || PythonTickForceDisabled) {
74+
if (!PyObject_HasAttrString(py_actor_instance, (char *)"tick") || PythonTickForceDisabled) {
7575
SetActorTickEnabled(false);
7676
}
7777

7878
if (!PythonDisableAutoBinding)
7979
ue_autobind_events_for_pyclass(py_uobject, py_actor_instance);
8080

8181

82-
if (!PyObject_HasAttrString(py_actor_instance, "begin_play"))
82+
if (!PyObject_HasAttrString(py_actor_instance, (char *)"begin_play"))
8383
return;
8484

85-
PyObject *bp_ret = PyObject_CallMethod(py_actor_instance, "begin_play", NULL);
85+
PyObject *bp_ret = PyObject_CallMethod(py_actor_instance, (char *)"begin_play", NULL);
8686
if (!bp_ret) {
8787
unreal_engine_py_log_error();
8888
return;
@@ -101,10 +101,10 @@ void APyActor::Tick(float DeltaTime)
101101

102102
FScopePythonGIL gil;
103103

104-
if (!PyObject_HasAttrString(py_actor_instance, "tick"))
104+
if (!PyObject_HasAttrString(py_actor_instance, (char *)"tick"))
105105
return;
106106

107-
PyObject *ret = PyObject_CallMethod(py_actor_instance, "tick", "f", DeltaTime);
107+
PyObject *ret = PyObject_CallMethod(py_actor_instance, (char *)"tick", (char *)"f", DeltaTime);
108108
if (!ret) {
109109
unreal_engine_py_log_error();
110110
return;
@@ -126,7 +126,7 @@ void APyActor::CallPythonActorMethod(FString method_name, FString args)
126126
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), NULL);
127127
}
128128
else {
129-
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
129+
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
130130
}
131131

132132
if (!ret) {
@@ -148,7 +148,7 @@ bool APyActor::CallPythonActorMethodBool(FString method_name, FString args)
148148
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), NULL);
149149
}
150150
else {
151-
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
151+
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
152152
}
153153
if (!ret) {
154154
unreal_engine_py_log_error();
@@ -176,7 +176,7 @@ FString APyActor::CallPythonActorMethodString(FString method_name, FString args)
176176
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), NULL);
177177
}
178178
else {
179-
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
179+
ret = PyObject_CallMethod(py_actor_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
180180
}
181181
if (!ret) {
182182
unreal_engine_py_log_error();
@@ -212,4 +212,4 @@ APyActor::~APyActor()
212212
#if UEPY_MEMORY_DEBUG
213213
UE_LOG(LogPython, Warning, TEXT("Python AActor (mapped to %p) wrapper XDECREF'ed"), py_uobject ? py_uobject->ue_object: nullptr);
214214
#endif
215-
}
215+
}

Source/UnrealEnginePython/Public/PyCharacter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void APyCharacter::BeginPlay()
6565
py_uobject = ue_get_python_wrapper(this);
6666

6767
if (py_uobject) {
68-
PyObject_SetAttrString(py_character_instance, "uobject", (PyObject *)py_uobject);
68+
PyObject_SetAttrString(py_character_instance, (char *)"uobject", (PyObject *)py_uobject);
6969
}
7070
else {
7171
UE_LOG(LogPython, Error, TEXT("Unable to set 'uobject' field in character wrapper class"));
@@ -74,18 +74,18 @@ void APyCharacter::BeginPlay()
7474
}
7575

7676
// disable ticking if no tick method is exposed
77-
if (!PyObject_HasAttrString(py_character_instance, "tick") || PythonTickForceDisabled) {
77+
if (!PyObject_HasAttrString(py_character_instance, (char *)"tick") || PythonTickForceDisabled) {
7878
SetActorTickEnabled(false);
7979
}
8080

8181
if (!PythonDisableAutoBinding)
8282
ue_autobind_events_for_pyclass(py_uobject, py_character_instance);
8383

84-
if (!PyObject_HasAttrString(py_character_instance, "begin_play")) {
84+
if (!PyObject_HasAttrString(py_character_instance, (char *)"begin_play")) {
8585
return;
8686
}
8787

88-
PyObject *bp_ret = PyObject_CallMethod(py_character_instance, "begin_play", NULL);
88+
PyObject *bp_ret = PyObject_CallMethod(py_character_instance, (char *)"begin_play", NULL);
8989
if (!bp_ret) {
9090
unreal_engine_py_log_error();
9191
return;
@@ -108,7 +108,7 @@ void APyCharacter::Tick(float DeltaTime)
108108

109109
// no need to check for method availability, we did it in begin_play
110110

111-
PyObject *ret = PyObject_CallMethod(py_character_instance, "tick", "f", DeltaTime);
111+
PyObject *ret = PyObject_CallMethod(py_character_instance, (char *)"tick", (char *)"f", DeltaTime);
112112
if (!ret) {
113113
unreal_engine_py_log_error();
114114
return;
@@ -131,7 +131,7 @@ void APyCharacter::CallPyCharacterMethod(FString method_name, FString args)
131131
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), NULL);
132132
}
133133
else {
134-
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
134+
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
135135
}
136136

137137
if (!ret) {
@@ -265,7 +265,7 @@ bool APyCharacter::CallPyCharacterMethodBool(FString method_name, FString args)
265265
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), NULL);
266266
}
267267
else {
268-
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
268+
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
269269
}
270270

271271

@@ -297,7 +297,7 @@ float APyCharacter::CallPyCharacterMethodFloat(FString method_name, FString args
297297
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), NULL);
298298
}
299299
else {
300-
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
300+
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
301301
}
302302

303303

@@ -332,7 +332,7 @@ FString APyCharacter::CallPyCharacterMethodString(FString method_name, FString a
332332
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), NULL);
333333
}
334334
else {
335-
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
335+
ret = PyObject_CallMethod(py_character_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
336336
}
337337

338338
if (!ret) {
@@ -375,4 +375,4 @@ APyCharacter::~APyCharacter()
375375
#if UEPY_MEMORY_DEBUG
376376
UE_LOG(LogPython, Warning, TEXT("Python ACharacter (mapped to %p) wrapper XDECREF'ed"), py_uobject ? py_uobject->ue_object : nullptr);
377377
#endif
378-
}
378+
}

Source/UnrealEnginePython/Public/PyPawn.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void APyPawn::BeginPlay()
6262
py_uobject = ue_get_python_wrapper(this);
6363

6464
if (py_uobject) {
65-
PyObject_SetAttrString(py_pawn_instance, "uobject", (PyObject *) py_uobject);
65+
PyObject_SetAttrString(py_pawn_instance, (char *)"uobject", (PyObject *) py_uobject);
6666
}
6767
else {
6868
UE_LOG(LogPython, Error, TEXT("Unable to set 'uobject' field in pawn wrapper class"));
@@ -71,17 +71,17 @@ void APyPawn::BeginPlay()
7171
}
7272

7373
// disable ticking if not required
74-
if (!PyObject_HasAttrString(py_pawn_instance, "tick") || PythonTickForceDisabled) {
74+
if (!PyObject_HasAttrString(py_pawn_instance, (char *)"tick") || PythonTickForceDisabled) {
7575
SetActorTickEnabled(false);
7676
}
7777

7878
if (!PythonDisableAutoBinding)
7979
ue_autobind_events_for_pyclass(py_uobject, py_pawn_instance);
8080

81-
if (!PyObject_HasAttrString(py_pawn_instance, "begin_play"))
81+
if (!PyObject_HasAttrString(py_pawn_instance, (char *)"begin_play"))
8282
return;
8383

84-
PyObject *bp_ret = PyObject_CallMethod(py_pawn_instance, "begin_play", NULL);
84+
PyObject *bp_ret = PyObject_CallMethod(py_pawn_instance, (char *)"begin_play", NULL);
8585
if (!bp_ret) {
8686
unreal_engine_py_log_error();
8787
return;
@@ -100,7 +100,7 @@ void APyPawn::Tick(float DeltaTime)
100100

101101
FScopePythonGIL gil;
102102

103-
PyObject *ret = PyObject_CallMethod(py_pawn_instance, "tick", "f", DeltaTime);
103+
PyObject *ret = PyObject_CallMethod(py_pawn_instance, (char *)"tick", (char *)"f", DeltaTime);
104104
if (!ret) {
105105
unreal_engine_py_log_error();
106106
return;
@@ -188,4 +188,4 @@ APyPawn::~APyPawn()
188188
#if UEPY_MEMORY_DEBUG
189189
UE_LOG(LogPython, Warning, TEXT("Python APawn (mapped to %p) wrapper XDECREF'ed"), py_uobject ? py_uobject->ue_object : nullptr);
190190
#endif
191-
}
191+
}

Source/UnrealEnginePython/Public/PythonComponent.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void UPythonComponent::BeginPlay()
6666
py_uobject = ue_get_python_wrapper(this);
6767

6868
if (py_uobject) {
69-
PyObject_SetAttrString(py_component_instance, "uobject", (PyObject *)py_uobject);
69+
PyObject_SetAttrString(py_component_instance, (char *)"uobject", (PyObject *)py_uobject);
7070
}
7171
else {
7272
UE_LOG(LogPython, Error, TEXT("Unable to set 'uobject' field in component wrapper class"));
@@ -75,18 +75,18 @@ void UPythonComponent::BeginPlay()
7575
}
7676

7777
// disable ticking if no tick method is exposed
78-
if (!PyObject_HasAttrString(py_component_instance, "tick") || PythonTickForceDisabled) {
78+
if (!PyObject_HasAttrString(py_component_instance, (char *)"tick") || PythonTickForceDisabled) {
7979
SetComponentTickEnabled(false);
8080
}
8181

8282
if (!PythonDisableAutoBinding)
8383
ue_autobind_events_for_pyclass(py_uobject, py_component_instance);
8484

85-
if (!PyObject_HasAttrString(py_component_instance, "begin_play")) {
85+
if (!PyObject_HasAttrString(py_component_instance, (char *)"begin_play")) {
8686
return;
8787
}
8888

89-
PyObject *bp_ret = PyObject_CallMethod(py_component_instance, "begin_play", NULL);
89+
PyObject *bp_ret = PyObject_CallMethod(py_component_instance, (char *)"begin_play", NULL);
9090
if (!bp_ret) {
9191
unreal_engine_py_log_error();
9292
return;
@@ -107,7 +107,7 @@ void UPythonComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo
107107

108108
// no need to check for method availability, we did it in begin_play
109109

110-
PyObject *ret = PyObject_CallMethod(py_component_instance, "tick", "f", DeltaTime);
110+
PyObject *ret = PyObject_CallMethod(py_component_instance, (char *)"tick", (char *)"f", DeltaTime);
111111
if (!ret) {
112112
unreal_engine_py_log_error();
113113
return;
@@ -128,7 +128,7 @@ void UPythonComponent::CallPythonComponentMethod(FString method_name, FString ar
128128
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), NULL);
129129
}
130130
else {
131-
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
131+
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
132132
}
133133

134134
if (!ret) {
@@ -246,7 +246,7 @@ bool UPythonComponent::CallPythonComponentMethodBool(FString method_name, FStrin
246246
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), NULL);
247247
}
248248
else {
249-
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
249+
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
250250
}
251251

252252

@@ -276,7 +276,7 @@ float UPythonComponent::CallPythonComponentMethodFloat(FString method_name, FStr
276276
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), NULL);
277277
}
278278
else {
279-
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
279+
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
280280
}
281281

282282

@@ -309,7 +309,7 @@ FString UPythonComponent::CallPythonComponentMethodString(FString method_name, F
309309
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), NULL);
310310
}
311311
else {
312-
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), "s", TCHAR_TO_UTF8(*args));
312+
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
313313
}
314314

315315
if (!ret) {
@@ -345,4 +345,4 @@ UPythonComponent::~UPythonComponent()
345345
#if UEPY_MEMORY_DEBUG
346346
UE_LOG(LogPython, Warning, TEXT("Python UActorComponent (mapped to %p) wrapper XDECREF'ed"), py_uobject ? py_uobject->ue_object : nullptr);
347347
#endif
348-
}
348+
}

Source/UnrealEnginePython/Public/PythonDelegate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void UPythonDelegate::PyInputHandler()
7474
void UPythonDelegate::PyInputAxisHandler(float value)
7575
{
7676
FScopePythonGIL gil;
77-
PyObject *ret = PyObject_CallFunction(py_callable, "f", value);
77+
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"f", value);
7878
if (!ret) {
7979
unreal_engine_py_log_error();
8080
return;
@@ -89,4 +89,4 @@ UPythonDelegate::~UPythonDelegate()
8989
#if UEPY_MEMORY_DEBUG
9090
UE_LOG(LogPython, Warning, TEXT("PythonDelegate callable XDECREF'ed"));
9191
#endif
92-
}
92+
}

Source/UnrealEnginePython/UnrealEnginePython.Build.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
public class UnrealEnginePython : ModuleRules
77
{
88

9-
private const string pythonHome = "python35";
10-
//private const string pythonHome = "python27";
9+
//private const string pythonHome = "python35";
10+
private const string pythonHome = "python27";
1111

1212
protected string PythonHome
1313
{
@@ -20,7 +20,6 @@ protected string PythonHome
2020
public UnrealEnginePython(TargetInfo Target)
2121
{
2222

23-
System.Console.WriteLine("Using Python at: " + PythonHome);
2423

2524
PublicIncludePaths.AddRange(
2625
new string[] {
@@ -79,6 +78,7 @@ public UnrealEnginePython(TargetInfo Target)
7978

8079
if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
8180
{
81+
System.Console.WriteLine("Using Python at: " + PythonHome);
8282
PublicIncludePaths.Add(PythonHome);
8383
PublicAdditionalLibraries.Add(Path.Combine(PythonHome, "libs", string.Format("{0}.lib", pythonHome)));
8484
}
@@ -89,13 +89,14 @@ public UnrealEnginePython(TargetInfo Target)
8989
string mac_python = "/Library/Frameworks/Python.framework/Versions/3.5/";
9090
PublicIncludePaths.Add(Path.Combine(mac_python, "include"));
9191
PublicAdditionalLibraries.Add(Path.Combine(mac_python, "lib", "libpython3.5m.dylib"));
92+
Definitions.Add(string.Format("UNREAL_ENGINE_PYTHON_ON_MAC=3"));
9293
}
9394
else if (pythonHome == "python27") {
9495
string mac_python = "/Library/Frameworks/Python.framework/Versions/2.7/";
9596
PublicIncludePaths.Add(Path.Combine(mac_python, "include"));
9697
PublicAdditionalLibraries.Add(Path.Combine(mac_python, "lib", "libpython2.7.dylib"));
98+
Definitions.Add(string.Format("UNREAL_ENGINE_PYTHON_ON_MAC=2"));
9799
}
98-
Definitions.Add(string.Format("UNREAL_ENGINE_PYTHON_ON_MAC=1"));
99100
}
100101

101102
}

0 commit comments

Comments
 (0)