Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for iOS with Python 3.6.6 #601

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/UnrealEnginePython/Private/PyCommandlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ int32 UPyCommandlet::Main(const FString& CommandLine)
argv[i] = (wchar_t*)malloc(PyArgv[i].Len() + 1);
#if PLATFORM_MAC || PLATFORM_LINUX
wcsncpy(argv[i], *PyArgv[i].ReplaceEscapedCharWithChar(), PyArgv[i].Len() + 1);
#elif PLATFORM_ANDROID
#elif PLATFORM_ANDROID || PLATFORM_IOS
wcsncpy(argv[i], (const wchar_t *)*PyArgv[i].ReplaceEscapedCharWithChar(), PyArgv[i].Len() + 1);
#else
wcscpy_s(argv[i], PyArgv[i].Len() + 1, *PyArgv[i].ReplaceEscapedCharWithChar());
#endif
#else
argv[i] = (char*)malloc(PyArgv[i].Len() + 1);
#if PLATFORM_MAC || PLATFORM_LINUX || PLATFORM_ANDROID
#if PLATFORM_MAC || PLATFORM_LINUX || PLATFORM_ANDROID || PLATFORM_IOS
strncpy(argv[i], TCHAR_TO_UTF8(*PyArgv[i].ReplaceEscapedCharWithChar()), PyArgv[i].Len() + 1);
#else
strcpy_s(argv[i], PyArgv[i].Len() + 1, TCHAR_TO_UTF8(*PyArgv[i].ReplaceEscapedCharWithChar()));
Expand Down
4 changes: 2 additions & 2 deletions Source/UnrealEnginePython/Private/Slate/UEPyIDetailsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static PyObject *py_ue_idetails_view_set_object(ue_PyIDetailsView *self, PyObjec
}

static PyMethodDef ue_PyIDetailsView_methods[] = {
#pragma warning(suppress: 4191)
#pragma warning(disable: 4191)
{ "set_object", (PyCFunction)py_ue_idetails_view_set_object, METH_VARARGS | METH_KEYWORDS, "" },
{ NULL } /* Sentinel */
};
Expand Down Expand Up @@ -93,4 +93,4 @@ ue_PyIDetailsView *py_ue_is_idetails_view(PyObject *obj)
return nullptr;
return (ue_PyIDetailsView *)obj;
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static PyObject *py_ue_istructure_details_view_get_widget(ue_PyIStructureDetails
}

static PyMethodDef ue_PyIStructureDetailsView_methods[] = {
#pragma warning(suppress: 4191)
#pragma warning(disable: 4191)
{ "set_structure_data", (PyCFunction)py_ue_istructure_details_view_set_structure_data, METH_VARARGS | METH_KEYWORDS, "" },
{ "get_widget", (PyCFunction)py_ue_istructure_details_view_get_widget, METH_VARARGS, "" },
{ NULL } /* Sentinel */
Expand Down Expand Up @@ -217,4 +217,4 @@ ue_PyIStructureDetailsView *py_ue_is_istructure_details_view(PyObject *obj)
return nullptr;
return (ue_PyIStructureDetailsView *)obj;
}
#endif
#endif
4 changes: 3 additions & 1 deletion Source/UnrealEnginePython/Private/Slate/UEPySCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ static PyObject *py_ue_scanvas_add_slot(ue_PySCanvas *self, PyObject * args, PyO
}

static PyMethodDef ue_PySCanvas_methods[] = {
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "add_slot", (PyCFunction)py_ue_scanvas_add_slot, METH_VARARGS | METH_KEYWORDS, "" },
{ "clear_children", (PyCFunction)py_ue_scanvas_clear_children, METH_VARARGS, "" },
{ NULL } /* Sentinel */
Expand Down
4 changes: 3 additions & 1 deletion Source/UnrealEnginePython/Private/Slate/UEPySGridPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ static PyObject *py_ue_sgrid_panel_add_slot(ue_PySGridPanel *self, PyObject * ar

static PyMethodDef ue_PySGridPanel_methods[] = {
{ "clear_children", (PyCFunction)py_ue_sgrid_panel_clear_children, METH_VARARGS, "" },
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "add_slot", (PyCFunction)py_ue_sgrid_panel_add_slot, METH_VARARGS | METH_KEYWORDS, "" },
{ NULL } /* Sentinel */
};
Expand Down
4 changes: 3 additions & 1 deletion Source/UnrealEnginePython/Private/Slate/UEPySHeaderRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ static PyObject *py_ue_sheader_row_add_column(ue_PySHeaderRow *self, PyObject *a
}

static PyMethodDef ue_PySHeaderRow_methods[] = {
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "add_column", (PyCFunction)py_ue_sheader_row_add_column, METH_VARARGS | METH_KEYWORDS, "" },
{ NULL } /* Sentinel */
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ static PyObject *py_ue_shorizontal_box_num_slots(ue_PySHorizontalBox *self, PyOb
}

static PyMethodDef ue_PySHorizontalBox_methods[] = {
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "add_slot", (PyCFunction)py_ue_shorizontal_box_add_slot, METH_VARARGS | METH_KEYWORDS, "" },
{ "num_slots", (PyCFunction)py_ue_shorizontal_box_num_slots, METH_VARARGS, "" },
{ NULL } /* Sentinel */
Expand Down
4 changes: 3 additions & 1 deletion Source/UnrealEnginePython/Private/Slate/UEPySOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ static PyObject *py_ue_soverlay_get_num_widgets(ue_PySOverlay *self, PyObject *
}

static PyMethodDef ue_PySOverlay_methods[] = {
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "add_slot", (PyCFunction)py_ue_soverlay_add_slot, METH_VARARGS | METH_KEYWORDS, "" },
{ "get_num_widgets", (PyCFunction)py_ue_soverlay_get_num_widgets, METH_VARARGS, "" },
{ NULL } /* Sentinel */
Expand Down
4 changes: 3 additions & 1 deletion Source/UnrealEnginePython/Private/Slate/UEPySScrollBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ static PyObject *py_ue_sscroll_box_clear_children(ue_PySScrollBox *self, PyObjec

static PyMethodDef ue_PySScrollBox_methods[] = {
{ "clear_children", (PyCFunction)py_ue_sscroll_box_clear_children, METH_VARARGS, "" },
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "add_slot", (PyCFunction)py_ue_sscroll_box_add_slot, METH_VARARGS | METH_KEYWORDS, "" },
{ NULL } /* Sentinel */
};
Expand Down
4 changes: 3 additions & 1 deletion Source/UnrealEnginePython/Private/Slate/UEPySSplitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ static PyObject *py_ue_ssplitter_add_slot(ue_PySSplitter *self, PyObject * args,
}

static PyMethodDef ue_PySSplitter_methods[] = {
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "add_slot", (PyCFunction)py_ue_ssplitter_add_slot, METH_VARARGS | METH_KEYWORDS, "" },
{ NULL } /* Sentinel */
};
Expand Down
4 changes: 3 additions & 1 deletion Source/UnrealEnginePython/Private/Slate/UEPySVerticalBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ static PyObject *py_ue_svertical_box_num_slots(ue_PySVerticalBox *self, PyObject
}

static PyMethodDef ue_PySVerticalBox_methods[] = {
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "add_slot", (PyCFunction)py_ue_svertical_box_add_slot, METH_VARARGS | METH_KEYWORDS, "" },
{ "num_slots", (PyCFunction)py_ue_svertical_box_num_slots, METH_VARARGS, "" },
{ NULL } /* Sentinel */
Expand Down
42 changes: 28 additions & 14 deletions Source/UnrealEnginePython/Private/UEPyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,17 @@ static PyMethodDef unreal_engine_methods[] = {

{ "redraw_all_viewports", py_unreal_engine_redraw_all_viewports, METH_VARARGS, "" },
{ "update_ui", py_unreal_engine_update_ui, METH_VARARGS, "" },

#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "create_detail_view", (PyCFunction)py_unreal_engine_create_detail_view, METH_VARARGS | METH_KEYWORDS, "" },
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "create_structure_detail_view", (PyCFunction)py_unreal_engine_create_structure_detail_view, METH_VARARGS | METH_KEYWORDS, "" },
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "create_property_view", (PyCFunction)py_unreal_engine_create_property_view, METH_VARARGS | METH_KEYWORDS, "" },

{ "open_editor_for_asset", py_unreal_engine_open_editor_for_asset, METH_VARARGS, "" },
Expand Down Expand Up @@ -368,8 +373,9 @@ static PyMethodDef unreal_engine_methods[] = {
{ "heightmap_import", py_unreal_engine_heightmap_import, METH_VARARGS, "" },

{ "play_preview_sound", py_unreal_engine_play_preview_sound, METH_VARARGS, "" },

#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "get_assets_by_filter", (PyCFunction)py_unreal_engine_get_assets_by_filter, METH_VARARGS | METH_KEYWORDS, "" },
{ "create_blueprint", py_unreal_engine_create_blueprint, METH_VARARGS, "" },
{ "create_blueprint_from_actor", py_unreal_engine_create_blueprint_from_actor, METH_VARARGS, "" },
Expand Down Expand Up @@ -468,7 +474,9 @@ static PyMethodDef unreal_engine_methods[] = {
{ "get_game_viewport_size", py_unreal_engine_get_game_viewport_size, METH_VARARGS, "" },

{ "get_game_viewport_client", py_unreal_engine_get_game_viewport_client, METH_VARARGS, "" },
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "open_color_picker", (PyCFunction)py_unreal_engine_open_color_picker, METH_VARARGS | METH_KEYWORDS, "" },
{ "destroy_color_picker", py_unreal_engine_destroy_color_picker, METH_VARARGS, "" },
{ "play_sound", py_unreal_engine_play_sound, METH_VARARGS, "" },
Expand Down Expand Up @@ -499,8 +507,9 @@ static PyMethodDef unreal_engine_methods[] = {
{ "clipboard_copy", py_unreal_engine_clipboard_copy, METH_VARARGS, "" },
{ "clipboard_paste", py_unreal_engine_clipboard_paste, METH_VARARGS, "" },


#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "copy_properties_for_unrelated_objects", (PyCFunction)py_unreal_engine_copy_properties_for_unrelated_objects, METH_VARARGS | METH_KEYWORDS, "" },


Expand Down Expand Up @@ -702,7 +711,9 @@ static PyMethodDef ue_PyUObject_methods[] = {

{ "find_function", (PyCFunction)py_ue_find_function, METH_VARARGS, "" },

#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "call_function", (PyCFunction)py_ue_call_function, METH_VARARGS | METH_KEYWORDS, "" },


Expand Down Expand Up @@ -856,7 +867,9 @@ static PyMethodDef ue_PyUObject_methods[] = {
{ "actor_has_component_of_type", (PyCFunction)py_ue_actor_has_component_of_type, METH_VARARGS, "" },

{ "actor_destroy", (PyCFunction)py_ue_actor_destroy, METH_VARARGS, "" },
#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "actor_spawn", (PyCFunction)py_ue_actor_spawn, METH_VARARGS | METH_KEYWORDS, "" },
{ "actor_has_tag", (PyCFunction)py_ue_actor_has_tag, METH_VARARGS, "" },
{ "component_has_tag", (PyCFunction)py_ue_component_has_tag, METH_VARARGS, "" },
Expand Down Expand Up @@ -1039,8 +1052,9 @@ static PyMethodDef ue_PyUObject_methods[] = {
{ "skeletal_mesh_get_required_bones", (PyCFunction)py_ue_skeletal_mesh_get_required_bones, METH_VARARGS, "" },
{ "skeletal_mesh_lods_num", (PyCFunction)py_ue_skeletal_mesh_lods_num, METH_VARARGS, "" },
{ "skeletal_mesh_sections_num", (PyCFunction)py_ue_skeletal_mesh_sections_num, METH_VARARGS, "" },

#pragma warning(suppress: 4191)
#ifdef _MSC_VER
#pragma warning(disable: 4191)
#endif
{ "skeletal_mesh_build_lod", (PyCFunction)py_ue_skeletal_mesh_build_lod, METH_VARARGS | METH_KEYWORDS, "" },
#endif
#if WITH_EDITOR
Expand Down Expand Up @@ -1697,9 +1711,9 @@ void unreal_engine_init_py_module()
ue_python_init_enumsimporter(new_unreal_engine_module);
ue_python_init_ustructsimporter(new_unreal_engine_module);

#if WITH_EDITOR
ue_python_init_ffoliage_instance(new_unreal_engine_module);

#if WITH_EDITOR
ue_python_init_fslowtask(new_unreal_engine_module);
ue_python_init_swidget(new_unreal_engine_module);
ue_python_init_farfilter(new_unreal_engine_module);
Expand Down
20 changes: 18 additions & 2 deletions Source/UnrealEnginePython/Private/UnrealEnginePython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,30 @@ void FUnrealEnginePythonModule::StartupModule()
BasePythonPath += FString(":") + UnrealEnginePython_OBBPath;
}

UE_LOG(LogPython, Warning, TEXT("Setting Base Path to %s"), *BasePythonPath);
UE_LOG(LogPython, Warning, TEXT("Setting Android Base Path to %s"), *BasePythonPath);

Py_SetPath(Py_DecodeLocale(TCHAR_TO_UTF8(*BasePythonPath), NULL));

#elif PLATFORM_IOS
FString IOSContentPath = IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*IFileManager::Get().GetFilenameOnDisk(*FPaths::ConvertRelativePathToFull(PROJECT_CONTENT_DIR)));
FString PyScriptsSearchPath = IOSContentPath / FString(TEXT("lib")) + FString(":") +
IOSContentPath / FString(TEXT("lib/stdlib.zip")) + FString(":") +
IOSContentPath / FString(TEXT("scripts")); // the name of directory must be lower-case.

Py_SetPath(Py_DecodeLocale(TCHAR_TO_UTF8(*PyScriptsSearchPath), NULL));

UE_LOG(LogPython, Log, TEXT("Setting IOS Python Scripts Search Path to %s"), *PyScriptsSearchPath);
#endif
#endif

#if PLATFORM_IOS || PLATFORM_ANDROID
Py_NoSiteFlag = 1;
Py_NoUserSiteDirectory = 1;

Py_InitializeEx(0);
#else
Py_Initialize();

#endif
PyEval_InitThreads();

#if WITH_EDITOR
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "UEPyFFoliageInstance.h"

#if WITH_EDITOR

#include "Wrappers/UEPyFVector.h"
#include "Wrappers/UEPyFRotator.h"
#include "Wrappers/UEPyFTransform.h"
Expand Down Expand Up @@ -257,4 +259,6 @@ PyObject *py_ue_new_ffoliage_instance(AInstancedFoliageActor *foliage_actor, UFo
ret->foliage_type = TWeakObjectPtr<UFoliageType>(foliage_type);
ret->instance_id = instance_id;
return (PyObject *)ret;
}
}

#endif
2 changes: 1 addition & 1 deletion Source/UnrealEnginePython/Public/UnrealEnginePython.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#elif PLATFORM_LINUX
#include <Python.h>
#include <structmember.h>
#elif PLATFORM_ANDROID
#elif PLATFORM_ANDROID || PLATFORM_IOS
#include <Python.h>
#include <structmember.h>
#elif PLATFORM_WINDOWS
Expand Down
30 changes: 30 additions & 0 deletions Source/UnrealEnginePython/UnrealEnginePython.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public UnrealEnginePython(TargetInfo Target)
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
string enableUnityBuild = System.Environment.GetEnvironmentVariable("UEP_ENABLE_UNITY_BUILD");
bFasterWithoutUnity = string.IsNullOrEmpty(enableUnityBuild);
string PluginDirectory = Path.Combine(ModuleDirectory, "..", "..");

PublicIncludePaths.AddRange(
new string[] {
Expand Down Expand Up @@ -271,6 +272,35 @@ public UnrealEnginePython(TargetInfo Target)
AdditionalPropertiesForReceipt.Add(new ReceiptProperty("AndroidPlugin", RelAPLPath));
}
#endif
else if (Target.Platform == UnrealTargetPlatform.IOS)
{
string PythonIOSLibsDirectory = Path.Combine(PluginDirectory, "python", "python36", "ios");

string includePath = Path.Combine(PythonIOSLibsDirectory, "Python", "Headers");
PublicIncludePaths.Add(includePath);

PublicLibraryPaths.AddRange(
new string[] {
Path.Combine(PythonIOSLibsDirectory, "BZip2"),
Path.Combine(PythonIOSLibsDirectory, "OpenSSL"),
Path.Combine(PythonIOSLibsDirectory, "Python"),
Path.Combine(PythonIOSLibsDirectory, "XZ"),
Path.Combine(PythonIOSLibsDirectory, "Sqlite3"),
});

string[] libraryPaths = new string[] {
Path.Combine(PythonIOSLibsDirectory, "BZip2", "libbzip2.a"),
Path.Combine(PythonIOSLibsDirectory, "OpenSSL", "libOpenSSL.a"),
Path.Combine(PythonIOSLibsDirectory, "Python", "libPython.a"),
Path.Combine(PythonIOSLibsDirectory, "XZ", "libxz.a"),
Path.Combine(PythonIOSLibsDirectory, "Sqlite3", "libsqlite3.tbd"),
};

foreach (string libraryPath in libraryPaths)
{
PublicAdditionalLibraries.Add(libraryPath);
}
}

}

Expand Down
Loading