diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-09 17:08:13 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-09 17:08:13 +0200 |
commit | aa9b3594e11498ca0977d87a9d0875d7fc107253 (patch) | |
tree | 8e4e3152088a56611822c6e881179e89e69bef13 /src/macros_and_utils.h | |
parent | 95932749a53f46ae5901798a17e1f0c4c33ac6b2 (diff) | |
download | lanes-aa9b3594e11498ca0977d87a9d0875d7fc107253.tar.gz lanes-aa9b3594e11498ca0977d87a9d0875d7fc107253.tar.bz2 lanes-aa9b3594e11498ca0977d87a9d0875d7fc107253.zip |
C++ migration: [[nodiscard]] everywhere. still have to check all std::ignore
Diffstat (limited to 'src/macros_and_utils.h')
-rw-r--r-- | src/macros_and_utils.h | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 47ce90c..31ae8bd 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h | |||
@@ -23,11 +23,13 @@ extern char const* debugspew_indent; | |||
23 | #define INDENT_BEGIN "%.*s " | 23 | #define INDENT_BEGIN "%.*s " |
24 | #define INDENT_END , (U ? U->debugspew_indent_depth.load(std::memory_order_relaxed) : 0), debugspew_indent | 24 | #define INDENT_END , (U ? U->debugspew_indent_depth.load(std::memory_order_relaxed) : 0), debugspew_indent |
25 | #define DEBUGSPEW_CODE(_code) _code | 25 | #define DEBUGSPEW_CODE(_code) _code |
26 | #define DEBUGSPEW_PARAM_COMMA( param_) param_, | 26 | #define DEBUGSPEW_OR_NOT(a_, b_) a_ |
27 | #define DEBUGSPEW_PARAM_COMMA(param_) param_, | ||
27 | #define DEBUGSPEW_COMMA_PARAM( param_) , param_ | 28 | #define DEBUGSPEW_COMMA_PARAM( param_) , param_ |
28 | #else // USE_DEBUG_SPEW() | 29 | #else // USE_DEBUG_SPEW() |
29 | #define DEBUGSPEW_CODE(_code) | 30 | #define DEBUGSPEW_CODE(_code) |
30 | #define DEBUGSPEW_PARAM_COMMA( param_) | 31 | #define DEBUGSPEW_OR_NOT(a_, b_) b_ |
32 | #define DEBUGSPEW_PARAM_COMMA(param_) | ||
31 | #define DEBUGSPEW_COMMA_PARAM( param_) | 33 | #define DEBUGSPEW_COMMA_PARAM( param_) |
32 | #endif // USE_DEBUG_SPEW() | 34 | #endif // USE_DEBUG_SPEW() |
33 | 35 | ||
@@ -130,20 +132,20 @@ inline void STACK_GROW(lua_State* L, int n_) | |||
130 | } | 132 | } |
131 | } | 133 | } |
132 | 134 | ||
133 | #define LUAG_FUNC( func_name) int LG_##func_name( lua_State* L) | 135 | #define LUAG_FUNC(func_name) [[nodiscard]] int LG_##func_name(lua_State* L) |
134 | 136 | ||
135 | // ################################################################################################# | 137 | // ################################################################################################# |
136 | 138 | ||
137 | // a small helper to extract a full userdata pointer from the stack in a safe way | 139 | // a small helper to extract a full userdata pointer from the stack in a safe way |
138 | template<typename T> | 140 | template<typename T> |
139 | T* lua_tofulluserdata(lua_State* L, int index_) | 141 | [[nodiscard]] T* lua_tofulluserdata(lua_State* L, int index_) |
140 | { | 142 | { |
141 | ASSERT_L(lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA); | 143 | ASSERT_L(lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA); |
142 | return static_cast<T*>(lua_touserdata(L, index_)); | 144 | return static_cast<T*>(lua_touserdata(L, index_)); |
143 | } | 145 | } |
144 | 146 | ||
145 | template<typename T> | 147 | template<typename T> |
146 | auto lua_tolightuserdata(lua_State* L, int index_) | 148 | [[nodiscard]] auto lua_tolightuserdata(lua_State* L, int index_) |
147 | { | 149 | { |
148 | ASSERT_L(lua_isnil(L, index_) || lua_islightuserdata(L, index_)); | 150 | ASSERT_L(lua_isnil(L, index_) || lua_islightuserdata(L, index_)); |
149 | if constexpr (std::is_pointer_v<T>) | 151 | if constexpr (std::is_pointer_v<T>) |
@@ -157,7 +159,7 @@ auto lua_tolightuserdata(lua_State* L, int index_) | |||
157 | } | 159 | } |
158 | 160 | ||
159 | template <typename T> | 161 | template <typename T> |
160 | T* lua_newuserdatauv(lua_State* L, int nuvalue_) | 162 | [[nodiscard]] T* lua_newuserdatauv(lua_State* L, int nuvalue_) |
161 | { | 163 | { |
162 | return static_cast<T*>(lua_newuserdatauv(L, sizeof(T), nuvalue_)); | 164 | return static_cast<T*>(lua_newuserdatauv(L, sizeof(T), nuvalue_)); |
163 | } | 165 | } |
@@ -175,6 +177,7 @@ using lua_Duration = std::chrono::template duration<lua_Number>; | |||
175 | 177 | ||
176 | // ################################################################################################# | 178 | // ################################################################################################# |
177 | 179 | ||
180 | // A unique type generator | ||
178 | template <typename T, auto = []{}> | 181 | template <typename T, auto = []{}> |
179 | struct Unique | 182 | struct Unique |
180 | { | 183 | { |