aboutsummaryrefslogtreecommitdiff
path: root/src/macros_and_utils.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/macros_and_utils.h28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h
index be331a1..dfde550 100644
--- a/src/macros_and_utils.h
+++ b/src/macros_and_utils.h
@@ -49,6 +49,7 @@ template <typename... ARGS>
49 49
50// ################################################################################################# 50// #################################################################################################
51 51
52#if LUA_VERSION_NUM >= 504
52// use this instead of Lua's luaL_typeerror 53// use this instead of Lua's luaL_typeerror
53template <typename... ARGS> 54template <typename... ARGS>
54[[noreturn]] static inline void raise_luaL_typeerror(lua_State* L_, int arg_, char const* tname_) 55[[noreturn]] static inline void raise_luaL_typeerror(lua_State* L_, int arg_, char const* tname_)
@@ -56,6 +57,7 @@ template <typename... ARGS>
56 std::ignore = luaL_typeerror(L_, arg_, tname_); // doesn't return 57 std::ignore = luaL_typeerror(L_, arg_, tname_); // doesn't return
57 assert(false); // we should never get here, but i'm paranoid 58 assert(false); // we should never get here, but i'm paranoid
58} 59}
60#endif // LUA_VERSION_NUM
59 61
60// ################################################################################################# 62// #################################################################################################
61 63
@@ -182,42 +184,42 @@ class StackChecker
182 184
183// ################################################################################################# 185// #################################################################################################
184 186
185inline void STACK_GROW(lua_State* L, int n_) 187inline void STACK_GROW(lua_State* L_, int n_)
186{ 188{
187 if (!lua_checkstack(L, n_)) { 189 if (!lua_checkstack(L_, n_)) {
188 raise_luaL_error(L, "Cannot grow stack!"); 190 raise_luaL_error(L_, "Cannot grow stack!");
189 } 191 }
190} 192}
191 193
192// ################################################################################################# 194// #################################################################################################
193 195
194#define LUAG_FUNC(func_name) [[nodiscard]] int LG_##func_name(lua_State* L) 196#define LUAG_FUNC(func_name) [[nodiscard]] int LG_##func_name(lua_State* L_)
195 197
196// ################################################################################################# 198// #################################################################################################
197 199
198// a small helper to extract a full userdata pointer from the stack in a safe way 200// a small helper to extract a full userdata pointer from the stack in a safe way
199template <typename T> 201template <typename T>
200[[nodiscard]] T* lua_tofulluserdata(lua_State* L, int index_) 202[[nodiscard]] T* lua_tofulluserdata(lua_State* L_, int index_)
201{ 203{
202 LUA_ASSERT(L, lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA); 204 LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_type(L_, index_) == LUA_TUSERDATA);
203 return static_cast<T*>(lua_touserdata(L, index_)); 205 return static_cast<T*>(lua_touserdata(L_, index_));
204} 206}
205 207
206template <typename T> 208template <typename T>
207[[nodiscard]] auto lua_tolightuserdata(lua_State* L, int index_) 209[[nodiscard]] auto lua_tolightuserdata(lua_State* L_, int index_)
208{ 210{
209 LUA_ASSERT(L, lua_isnil(L, index_) || lua_islightuserdata(L, index_)); 211 LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_islightuserdata(L_, index_));
210 if constexpr (std::is_pointer_v<T>) { 212 if constexpr (std::is_pointer_v<T>) {
211 return static_cast<T>(lua_touserdata(L, index_)); 213 return static_cast<T>(lua_touserdata(L_, index_));
212 } else { 214 } else {
213 return static_cast<T*>(lua_touserdata(L, index_)); 215 return static_cast<T*>(lua_touserdata(L_, index_));
214 } 216 }
215} 217}
216 218
217template <typename T> 219template <typename T>
218[[nodiscard]] T* lua_newuserdatauv(lua_State* L, int nuvalue_) 220[[nodiscard]] T* lua_newuserdatauv(lua_State* L_, int nuvalue_)
219{ 221{
220 return static_cast<T*>(lua_newuserdatauv(L, sizeof(T), nuvalue_)); 222 return static_cast<T*>(lua_newuserdatauv(L_, sizeof(T), nuvalue_));
221} 223}
222 224
223// ################################################################################################# 225// #################################################################################################