Repository navigation
Expand file tree
/
Copy pathUnrealEnginePython.h
More file actions
90 lines (63 loc) · 1.92 KB
/
Copy pathUnrealEnginePython.h
File metadata and controls
90 lines (63 loc) · 1.92 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#pragma once
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wdelete-non-virtual-dtor"
#endif
#include "ModuleManager.h"
#include "Engine.h"
#include "Runtime/Launch/Resources/Version.h"
#include "Runtime/SlateCore/Public/Styling/ISlateStyle.h"
#include "Runtime/SlateCore/Public/Styling/SlateStyle.h"
// We need to make sure reference structs do not mistaken for callable
#define PyCalllable_Check_Extended(value) PyCallable_Check(value) && py_ue_is_uscriptstruct(value) == nullptr
#if ENGINE_MINOR_VERSION >= 18
#define FStringAssetReference FSoftObjectPath
#endif
DECLARE_LOG_CATEGORY_EXTERN(LogPython, Log, All);
class UNREALENGINEPYTHON_API FUnrealEnginePythonModule : public IModuleInterface
{
public:
bool PythonGILAcquire();
void PythonGILRelease();
virtual void StartupModule() override;
virtual void ShutdownModule() override;
void RunString(char *);
void RunStringSandboxed(char *);
void RunFile(char *);
void RunFileSandboxed(char *, void(*callback)(void *arg), void *arg);
void UESetupPythonInterpreter(bool);
FString ScriptsPath;
FString ZipPath;
FString AdditionalModulesPath;
bool BrutalFinalize;
// pep8ize a string using various strategy (currently only autopep8 is supported)
FString Pep8ize(FString Code);
private:
void *ue_python_gil;
// used by console
void *main_dict;
void *local_dict;
void *main_module;
TSharedPtr<FSlateStyleSet> StyleSet;
};
struct FScopePythonGIL
{
FScopePythonGIL()
{
#if defined(UEPY_THREADING)
UnrealEnginePythonModule = FModuleManager::LoadModuleChecked<FUnrealEnginePythonModule>("UnrealEnginePython");
safeForRelease = UnrealEnginePythonModule.PythonGILAcquire();
#endif
}
~FScopePythonGIL()
{
#if defined(UEPY_THREADING)
if (safeForRelease)
{
UnrealEnginePythonModule.PythonGILRelease();
}
#endif
}
FUnrealEnginePythonModule UnrealEnginePythonModule;
bool safeForRelease;
};