aboutsummaryrefslogtreecommitdiff
path: root/src/debug.h
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-10-07 09:29:49 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-10-07 09:29:49 +0200
commite939e5e6a894a042d3301e47faa05264445f27f6 (patch)
treee913615e3fd0ed9e94d9494d6e266420dd7a771b /src/debug.h
parentb064bedccebe511b96c9d99d689d6634f5873ec2 (diff)
downloadlanes-e939e5e6a894a042d3301e47faa05264445f27f6.tar.gz
lanes-e939e5e6a894a042d3301e47faa05264445f27f6.tar.bz2
lanes-e939e5e6a894a042d3301e47faa05264445f27f6.zip
Internal improvements: new strong types StackIndex and KeeperIndex
Diffstat (limited to 'src/debug.h')
-rw-r--r--src/debug.h20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/debug.h b/src/debug.h
index e96632d..0f5c6bc 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -2,6 +2,7 @@
2 2
3#include "lanesconf.h" 3#include "lanesconf.h"
4#include "luaerrors.h" 4#include "luaerrors.h"
5#include "unique.hpp"
5 6
6// ################################################################################################# 7// #################################################################################################
7 8
@@ -18,7 +19,7 @@ inline SourceLocation Where(std::source_location const& where_ = std::source_loc
18 return std::make_tuple(_fileName, where_.line(), _func); 19 return std::make_tuple(_fileName, where_.line(), _func);
19} 20}
20 21
21inline void LUA_ASSERT_IMPL(lua_State* const L_, bool cond_, std::string_view const& txt_, SourceLocation const& where_ = Where()) 22inline void LUA_ASSERT_IMPL(lua_State* const L_, bool const cond_, std::string_view const& txt_, SourceLocation const& where_ = Where())
22{ 23{
23 if (!cond_) { 24 if (!cond_) {
24 raise_luaL_error(L_, "%s:%d: LUA_ASSERT '%s' IN %s", std::get<0>(where_).data(), std::get<1>(where_), txt_.data(), std::get<2>(where_).data()); 25 raise_luaL_error(L_, "%s:%d: LUA_ASSERT '%s' IN %s", std::get<0>(where_).data(), std::get<1>(where_), txt_.data(), std::get<2>(where_).data());
@@ -35,19 +36,8 @@ class StackChecker
35 int oldtop; 36 int oldtop;
36 37
37 public: 38 public:
38 struct Relative 39 using Relative = Unique<int>;
39 { 40 using Absolute = Unique<int>;
40 int const offset;
41
42 operator int() const { return offset; }
43 };
44
45 struct Absolute
46 {
47 int const offset;
48
49 operator int() const { return offset; }
50 };
51 41
52 StackChecker(lua_State* const L_, Relative const offset_, SourceLocation const& where_ = Where()) 42 StackChecker(lua_State* const L_, Relative const offset_, SourceLocation const& where_ = Where())
53 : L{ L_ } 43 : L{ L_ }
@@ -77,7 +67,7 @@ class StackChecker
77 } 67 }
78 68
79 // verify if the distance between the current top and the initial one is what we expect 69 // verify if the distance between the current top and the initial one is what we expect
80 void check(int expected_, SourceLocation const& where_ = Where()) 70 void check(int const expected_, SourceLocation const& where_ = Where())
81 { 71 {
82 if (expected_ != LUA_MULTRET) { 72 if (expected_ != LUA_MULTRET) {
83 int const _actual{ lua_gettop(L) - oldtop }; 73 int const _actual{ lua_gettop(L) - oldtop };