diff options
Diffstat (limited to '')
-rw-r--r-- | src/macros_and_utils.h | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 63bc8d1..31027d6 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h | |||
@@ -11,6 +11,7 @@ extern "C" { | |||
11 | #endif // __cplusplus | 11 | #endif // __cplusplus |
12 | 12 | ||
13 | #include <cassert> | 13 | #include <cassert> |
14 | #include <tuple> | ||
14 | #include <type_traits> | 15 | #include <type_traits> |
15 | 16 | ||
16 | #define USE_DEBUG_SPEW() 0 | 17 | #define USE_DEBUG_SPEW() 0 |
@@ -71,7 +72,7 @@ class StackChecker | |||
71 | if ((offset_ < 0) || (m_oldtop < 0)) | 72 | if ((offset_ < 0) || (m_oldtop < 0)) |
72 | { | 73 | { |
73 | assert(false); | 74 | assert(false); |
74 | (void) luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), offset_, file_, line_); | 75 | std::ignore = luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), offset_, file_, line_); |
75 | } | 76 | } |
76 | } | 77 | } |
77 | 78 | ||
@@ -82,7 +83,7 @@ class StackChecker | |||
82 | if (lua_gettop(m_L) != pos_) | 83 | if (lua_gettop(m_L) != pos_) |
83 | { | 84 | { |
84 | assert(false); | 85 | assert(false); |
85 | (void) luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), pos_, file_, line_); | 86 | std::ignore = luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), pos_, file_, line_); |
86 | } | 87 | } |
87 | } | 88 | } |
88 | 89 | ||
@@ -102,7 +103,7 @@ class StackChecker | |||
102 | if (actual != expected_) | 103 | if (actual != expected_) |
103 | { | 104 | { |
104 | assert(false); | 105 | assert(false); |
105 | luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%d", actual, expected_, file_, line_); | 106 | std::ignore = luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%d", actual, expected_, file_, line_); |
106 | } | 107 | } |
107 | } | 108 | } |
108 | } | 109 | } |
@@ -121,11 +122,15 @@ class StackChecker | |||
121 | inline void STACK_GROW(lua_State* L, int n_) | 122 | inline void STACK_GROW(lua_State* L, int n_) |
122 | { | 123 | { |
123 | if (!lua_checkstack(L, n_)) | 124 | if (!lua_checkstack(L, n_)) |
124 | luaL_error(L, "Cannot grow stack!"); | 125 | { |
126 | std::ignore = luaL_error(L, "Cannot grow stack!"); | ||
127 | } | ||
125 | } | 128 | } |
126 | 129 | ||
127 | #define LUAG_FUNC( func_name) int LG_##func_name( lua_State* L) | 130 | #define LUAG_FUNC( func_name) int LG_##func_name( lua_State* L) |
128 | 131 | ||
132 | // ################################################################################################# | ||
133 | |||
129 | // a small helper to extract a full userdata pointer from the stack in a safe way | 134 | // a small helper to extract a full userdata pointer from the stack in a safe way |
130 | template<typename T> | 135 | template<typename T> |
131 | T* lua_tofulluserdata(lua_State* L, int index_) | 136 | T* lua_tofulluserdata(lua_State* L, int index_) |
@@ -153,3 +158,12 @@ T* lua_newuserdatauv(lua_State* L, int nuvalue_) | |||
153 | { | 158 | { |
154 | return static_cast<T*>(lua_newuserdatauv(L, sizeof(T), nuvalue_)); | 159 | return static_cast<T*>(lua_newuserdatauv(L, sizeof(T), nuvalue_)); |
155 | } | 160 | } |
161 | |||
162 | // ################################################################################################# | ||
163 | |||
164 | // use this instead of Lua's lua_error if possible | ||
165 | [[noreturn]] static inline void raise_lua_error(lua_State* L) | ||
166 | { | ||
167 | std::ignore = lua_error(L); // doesn't return | ||
168 | assert(false); // we should never get here, but i'm paranoid | ||
169 | } | ||