diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-09 15:49:18 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-09 15:49:18 +0200 |
commit | 95932749a53f46ae5901798a17e1f0c4c33ac6b2 (patch) | |
tree | 327d85f6f634edfacc01dc587492d96f9200344d /src/macros_and_utils.h | |
parent | 98ff4191c2cd215c7d6a429e9ddd66f7a6a30316 (diff) | |
download | lanes-95932749a53f46ae5901798a17e1f0c4c33ac6b2.tar.gz lanes-95932749a53f46ae5901798a17e1f0c4c33ac6b2.tar.bz2 lanes-95932749a53f46ae5901798a17e1f0c4c33ac6b2.zip |
C++ migration: use strong type safety for source and destination states in transfer functions
Diffstat (limited to 'src/macros_and_utils.h')
-rw-r--r-- | src/macros_and_utils.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 997b452..47ce90c 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h | |||
@@ -44,8 +44,8 @@ extern char const* debugspew_indent; | |||
44 | 44 | ||
45 | #else // NDEBUG | 45 | #else // NDEBUG |
46 | 46 | ||
47 | #define _ASSERT_L( L, cond_) if( (cond_) == 0) { (void) luaL_error( L, "ASSERT failed: %s:%d '%s'", __FILE__, __LINE__, #cond_);} | 47 | #define _ASSERT_L(L, cond_) if( (cond_) == 0) { (void) luaL_error(L, "ASSERT failed: %s:%d '%s'", __FILE__, __LINE__, #cond_);} |
48 | #define STACK_DUMP( L) luaG_dump( L) | 48 | #define STACK_DUMP(L) luaG_dump(L) |
49 | 49 | ||
50 | class StackChecker | 50 | class StackChecker |
51 | { | 51 | { |
@@ -172,3 +172,17 @@ T* lua_newuserdatauv(lua_State* L, int nuvalue_) | |||
172 | } | 172 | } |
173 | 173 | ||
174 | using lua_Duration = std::chrono::template duration<lua_Number>; | 174 | using lua_Duration = std::chrono::template duration<lua_Number>; |
175 | |||
176 | // ################################################################################################# | ||
177 | |||
178 | template <typename T, auto = []{}> | ||
179 | struct Unique | ||
180 | { | ||
181 | T m_val; | ||
182 | Unique() = default; | ||
183 | operator T() const { return m_val; } | ||
184 | explicit Unique(T b_) : m_val{ b_ } {} | ||
185 | }; | ||
186 | |||
187 | using Source = Unique<lua_State*>; | ||
188 | using Dest = Unique<lua_State*>; | ||