diff options
Diffstat (limited to 'src/universe.h')
-rw-r--r-- | src/universe.h | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/universe.h b/src/universe.h index bdc871d..128c4d9 100644 --- a/src/universe.h +++ b/src/universe.h | |||
@@ -1,7 +1,8 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #ifdef __cplusplus | 3 | #ifdef __cplusplus |
4 | extern "C" { | 4 | extern "C" |
5 | { | ||
5 | #endif // __cplusplus | 6 | #endif // __cplusplus |
6 | #include "lua.h" | 7 | #include "lua.h" |
7 | #ifdef __cplusplus | 8 | #ifdef __cplusplus |
@@ -20,9 +21,7 @@ struct DeepPrelude; | |||
20 | struct Keepers; | 21 | struct Keepers; |
21 | class Lane; | 22 | class Lane; |
22 | 23 | ||
23 | /* | 24 | // Do we want to activate full lane tracking feature? |
24 | * Do we want to activate full lane tracking feature? (EXPERIMENTAL) | ||
25 | */ | ||
26 | #define HAVE_LANE_TRACKING() 1 | 25 | #define HAVE_LANE_TRACKING() 1 |
27 | 26 | ||
28 | // ################################################################################################# | 27 | // ################################################################################################# |
@@ -31,7 +30,6 @@ class Lane; | |||
31 | class AllocatorDefinition | 30 | class AllocatorDefinition |
32 | { | 31 | { |
33 | public: | 32 | public: |
34 | |||
35 | lua_Alloc m_allocF{ nullptr }; | 33 | lua_Alloc m_allocF{ nullptr }; |
36 | void* m_allocUD{ nullptr }; | 34 | void* m_allocUD{ nullptr }; |
37 | 35 | ||
@@ -76,10 +74,10 @@ class AllocatorDefinition | |||
76 | // ################################################################################################# | 74 | // ################################################################################################# |
77 | 75 | ||
78 | // mutex-protected allocator for use with Lua states that share a non-threadsafe allocator | 76 | // mutex-protected allocator for use with Lua states that share a non-threadsafe allocator |
79 | class ProtectedAllocator : public AllocatorDefinition | 77 | class ProtectedAllocator |
78 | : public AllocatorDefinition | ||
80 | { | 79 | { |
81 | private: | 80 | private: |
82 | |||
83 | std::mutex m_lock; | 81 | std::mutex m_lock; |
84 | 82 | ||
85 | [[nodiscard]] static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_) | 83 | [[nodiscard]] static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_) |
@@ -90,14 +88,13 @@ class ProtectedAllocator : public AllocatorDefinition | |||
90 | } | 88 | } |
91 | 89 | ||
92 | public: | 90 | public: |
93 | |||
94 | // we are not like our base class: we can't be created inside a full userdata (or we would have to install a metatable and __gc handler to destroy ourselves properly) | 91 | // we are not like our base class: we can't be created inside a full userdata (or we would have to install a metatable and __gc handler to destroy ourselves properly) |
95 | [[nodiscard]] static void* operator new(size_t size_, lua_State* L) noexcept = delete; | 92 | [[nodiscard]] static void* operator new(size_t size_, lua_State* L) noexcept = delete; |
96 | static void operator delete(void* p_, lua_State* L) = delete; | 93 | static void operator delete(void* p_, lua_State* L) = delete; |
97 | 94 | ||
98 | AllocatorDefinition makeDefinition() | 95 | AllocatorDefinition makeDefinition() |
99 | { | 96 | { |
100 | return AllocatorDefinition{ protected_lua_Alloc, this}; | 97 | return AllocatorDefinition{ protected_lua_Alloc, this }; |
101 | } | 98 | } |
102 | 99 | ||
103 | void installIn(lua_State* L) | 100 | void installIn(lua_State* L) |
@@ -108,8 +105,7 @@ class ProtectedAllocator : public AllocatorDefinition | |||
108 | void removeFrom(lua_State* L) | 105 | void removeFrom(lua_State* L) |
109 | { | 106 | { |
110 | // remove the protected allocator, if any | 107 | // remove the protected allocator, if any |
111 | if (m_allocF != nullptr) | 108 | if (m_allocF != nullptr) { |
112 | { | ||
113 | // install the non-protected allocator | 109 | // install the non-protected allocator |
114 | lua_setallocf(L, m_allocF, m_allocUD); | 110 | lua_setallocf(L, m_allocF, m_allocUD); |
115 | } | 111 | } |
@@ -123,7 +119,6 @@ class ProtectedAllocator : public AllocatorDefinition | |||
123 | class Universe | 119 | class Universe |
124 | { | 120 | { |
125 | public: | 121 | public: |
126 | |||
127 | #ifdef PLATFORM_LINUX | 122 | #ifdef PLATFORM_LINUX |
128 | // Linux needs to check, whether it's been run as root | 123 | // Linux needs to check, whether it's been run as root |
129 | bool const m_sudo{ geteuid() == 0 }; | 124 | bool const m_sudo{ geteuid() == 0 }; |
@@ -197,11 +192,9 @@ void universe_store(lua_State* L, Universe* U); | |||
197 | class DebugSpewIndentScope | 192 | class DebugSpewIndentScope |
198 | { | 193 | { |
199 | private: | 194 | private: |
200 | |||
201 | Universe* const U; | 195 | Universe* const U; |
202 | 196 | ||
203 | public: | 197 | public: |
204 | |||
205 | static char const* const debugspew_indent; | 198 | static char const* const debugspew_indent; |
206 | 199 | ||
207 | DebugSpewIndentScope(Universe* U_) | 200 | DebugSpewIndentScope(Universe* U_) |