Repository navigation
Expand file tree
/
Copy pathUnrealEnginePython.cpp
More file actions
48 lines (30 loc) · 1.57 KB
/
Copy pathUnrealEnginePython.cpp
File metadata and controls
48 lines (30 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "UnrealEnginePythonPrivatePCH.h"
void unreal_engine_init_py_module();
#define LOCTEXT_NAMESPACE "FUnrealEnginePythonModule"
void FUnrealEnginePythonModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
Py_Initialize();
unreal_engine_init_py_module();
PyObject *py_sys = PyImport_ImportModule("sys");
PyObject *py_sys_dict = PyModule_GetDict(py_sys);
PyObject *py_path = PyDict_GetItemString(py_sys_dict, "path");
char *zip_path = TCHAR_TO_UTF8(*FPaths::Combine(*FPaths::GameContentDir(), UTF8_TO_TCHAR("python35.zip")));
PyObject *py_zip_path = PyUnicode_FromString(zip_path);
PyList_Insert(py_path, 0, py_zip_path);
char *scripts_path = TCHAR_TO_UTF8(*FPaths::Combine(*FPaths::GameContentDir(), UTF8_TO_TCHAR("Scripts")));
PyObject *py_scripts_path = PyUnicode_FromString(scripts_path);
PyList_Insert(py_path, 0, py_scripts_path);
UE_LOG(LogPython, Log , TEXT("Python VM initialized: %s"), UTF8_TO_TCHAR(Py_GetVersion()));
UE_LOG(LogPython, Log, TEXT("Python Scripts search path: %s"), UTF8_TO_TCHAR(scripts_path));
}
void FUnrealEnginePythonModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
UE_LOG(LogPython, Log, TEXT("Goodbye Python"));
Py_Finalize();
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FUnrealEnginePythonModule, UnrealEnginePython)