diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-24 14:49:22 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-24 14:49:22 +0200 |
commit | 5c52bacfda43024ba17f5b1188b0b67e4f30c887 (patch) | |
tree | 6a349d50c276b6463cbc8c079c668100c7de4f99 /src/macros_and_utils.h | |
parent | ce7006e3c063fc1383c23d2e0e36917b31d04e3f (diff) | |
download | lanes-5c52bacfda43024ba17f5b1188b0b67e4f30c887.tar.gz lanes-5c52bacfda43024ba17f5b1188b0b67e4f30c887.tar.bz2 lanes-5c52bacfda43024ba17f5b1188b0b67e4f30c887.zip |
ASSERT_L → LUA_ASSERT
Diffstat (limited to 'src/macros_and_utils.h')
-rw-r--r-- | src/macros_and_utils.h | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index c01363a..edda76e 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h | |||
@@ -34,7 +34,7 @@ using namespace std::chrono_literals; | |||
34 | 34 | ||
35 | #ifdef NDEBUG | 35 | #ifdef NDEBUG |
36 | 36 | ||
37 | #define _ASSERT_L(lua,c) //nothing | 37 | #define LUA_ASSERT(L,c) ; //nothing |
38 | 38 | ||
39 | #define STACK_CHECK_START_REL(L, offset_) | 39 | #define STACK_CHECK_START_REL(L, offset_) |
40 | #define STACK_CHECK_START_ABS(L, offset_) | 40 | #define STACK_CHECK_START_ABS(L, offset_) |
@@ -44,7 +44,15 @@ using namespace std::chrono_literals; | |||
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 | inline void LUA_ASSERT_IMPL(lua_State* L_, bool cond_, char const* file_, size_t const line_, char const* txt_) |
48 | { | ||
49 | if (!cond_) | ||
50 | { | ||
51 | luaL_error(L_, "LUA_ASSERT %s:%llu '%s'", file_, line_, txt_); // doesn't return | ||
52 | } | ||
53 | } | ||
54 | |||
55 | #define LUA_ASSERT(L_, cond_) LUA_ASSERT_IMPL(L_, cond_, __FILE__, __LINE__, #cond_) | ||
48 | 56 | ||
49 | class StackChecker | 57 | class StackChecker |
50 | { | 58 | { |
@@ -74,7 +82,7 @@ class StackChecker | |||
74 | if ((offset_ < 0) || (m_oldtop < 0)) | 82 | if ((offset_ < 0) || (m_oldtop < 0)) |
75 | { | 83 | { |
76 | assert(false); | 84 | assert(false); |
77 | luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), offset_, file_, line_); // doesn't return | 85 | luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), offset_, file_, line_); // doesn't return |
78 | } | 86 | } |
79 | } | 87 | } |
80 | 88 | ||
@@ -85,7 +93,7 @@ class StackChecker | |||
85 | if (lua_gettop(m_L) != pos_) | 93 | if (lua_gettop(m_L) != pos_) |
86 | { | 94 | { |
87 | assert(false); | 95 | assert(false); |
88 | luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), pos_, file_, line_); // doesn't return | 96 | luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), pos_, file_, line_); // doesn't return |
89 | } | 97 | } |
90 | } | 98 | } |
91 | 99 | ||
@@ -105,7 +113,7 @@ class StackChecker | |||
105 | if (actual != expected_) | 113 | if (actual != expected_) |
106 | { | 114 | { |
107 | assert(false); | 115 | assert(false); |
108 | luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%d", actual, expected_, file_, line_); // doesn't return | 116 | luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%llu", actual, expected_, file_, line_); // doesn't return |
109 | } | 117 | } |
110 | } | 118 | } |
111 | } | 119 | } |
@@ -119,8 +127,6 @@ class StackChecker | |||
119 | 127 | ||
120 | #endif // NDEBUG | 128 | #endif // NDEBUG |
121 | 129 | ||
122 | #define ASSERT_L(c) _ASSERT_L(L,c) | ||
123 | |||
124 | inline void STACK_GROW(lua_State* L, int n_) | 130 | inline void STACK_GROW(lua_State* L, int n_) |
125 | { | 131 | { |
126 | if (!lua_checkstack(L, n_)) | 132 | if (!lua_checkstack(L, n_)) |
@@ -137,14 +143,14 @@ inline void STACK_GROW(lua_State* L, int n_) | |||
137 | template<typename T> | 143 | template<typename T> |
138 | [[nodiscard]] T* lua_tofulluserdata(lua_State* L, int index_) | 144 | [[nodiscard]] T* lua_tofulluserdata(lua_State* L, int index_) |
139 | { | 145 | { |
140 | ASSERT_L(lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA); | 146 | LUA_ASSERT(L, lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA); |
141 | return static_cast<T*>(lua_touserdata(L, index_)); | 147 | return static_cast<T*>(lua_touserdata(L, index_)); |
142 | } | 148 | } |
143 | 149 | ||
144 | template<typename T> | 150 | template<typename T> |
145 | [[nodiscard]] auto lua_tolightuserdata(lua_State* L, int index_) | 151 | [[nodiscard]] auto lua_tolightuserdata(lua_State* L, int index_) |
146 | { | 152 | { |
147 | ASSERT_L(lua_isnil(L, index_) || lua_islightuserdata(L, index_)); | 153 | LUA_ASSERT(L, lua_isnil(L, index_) || lua_islightuserdata(L, index_)); |
148 | if constexpr (std::is_pointer_v<T>) | 154 | if constexpr (std::is_pointer_v<T>) |
149 | { | 155 | { |
150 | return static_cast<T>(lua_touserdata(L, index_)); | 156 | return static_cast<T>(lua_touserdata(L, index_)); |