@@ -39,10 +39,12 @@ inline namespace sol2_tests_exhaustive {
39
39
40
40
inline constexpr int FAILURE_CONSTANT = 1000 ;
41
41
42
+ inline constexpr int LINK_CONSTANT = 0xA837 ;
43
+
42
44
inline int ex_f0 (sol::exhaustive<std::vector<Link>> ex_vec) {
43
45
const auto & vec = ex_vec.value ();
44
46
for (const auto & elem : vec) {
45
- REQUIRE (elem.value == 0 );
47
+ REQUIRE (elem.value == LINK_CONSTANT );
46
48
}
47
49
return 0 ;
48
50
}
@@ -56,10 +58,11 @@ inline namespace sol2_tests_exhaustive {
56
58
return 1 ;
57
59
}
58
60
59
- inline int ex_f2 (sol::exhaustive<std::vector<NonLink>> ex_vec) {
61
+ inline int ex_f2 (sol::exhaustive<std::vector<NonLink>> ex_vec, sol::this_state this_lua ) {
60
62
const auto & vec = ex_vec.value ();
63
+ void * address = static_cast <void *>(this_lua.lua_state ());
61
64
for (const auto & elem : vec) {
62
- REQUIRE (elem.value == nullptr );
65
+ REQUIRE (elem.value == address );
63
66
}
64
67
return 2 ;
65
68
}
@@ -74,9 +77,11 @@ TEST_CASE("large_integer/bool", "pass bool integral value to and from lua") {
74
77
sol::state lua;
75
78
lua.open_libraries (sol::lib::base);
76
79
80
+ void * address = lua.lua_state ();
81
+
77
82
lua[" FAILURE_CONSTANT" ] = FAILURE_CONSTANT;
78
- lua[" link_obj" ] = Link { 0 };
79
- lua[" nonlink_obj" ] = NonLink { nullptr };
83
+ lua[" link_obj" ] = Link { LINK_CONSTANT };
84
+ lua[" nonlink_obj" ] = NonLink { address };
80
85
81
86
sol::optional<sol::error> setup_result = lua.safe_script (R"(
82
87
expect0_0 = { link_obj, link_obj, link_obj, link_obj }
@@ -89,22 +94,31 @@ TEST_CASE("large_integer/bool", "pass bool integral value to and from lua") {
89
94
REQUIRE_FALSE (setup_result.has_value ());
90
95
91
96
lua.set_function (" get_table_exhaustive" , sol::overload (ex_f0, ex_f1, ex_f2, ex_ffail));
92
-
93
- sol::optional<sol::error> result = lua.safe_script (R"(
94
- result0_0 = get_table_exhaustive(expect0_0)
95
- assert(result0_0 == 0)
96
- result0_1 = get_table_exhaustive(expect0_1)
97
- assert(result0_1 == FAILURE_CONSTANT)
98
-
99
- result1_0 = get_table_exhaustive(expect1_0)
100
- assert(result1_0 == 1)
101
- result1_1 = get_table_exhaustive(expect1_1)
102
- assert(result1_1 == FAILURE_CONSTANT)
103
-
104
- result2_0 = get_table_exhaustive(expect2_0)
105
- assert(result2_0 == 2)
106
- result2_1 = get_table_exhaustive(expect2_1)
107
- assert(result2_1 == FAILURE_CONSTANT)
108
- )" );
109
- REQUIRE_FALSE (result.has_value ());
97
+ {
98
+ sol::optional<sol::error> result = lua.safe_script (R"(
99
+ result0_0 = get_table_exhaustive(expect0_0)
100
+ assert(result0_0 == 0)
101
+ result0_1 = get_table_exhaustive(expect0_1)
102
+ assert(result0_1 == FAILURE_CONSTANT)
103
+ )" );
104
+ REQUIRE_FALSE (result.has_value ());
105
+ }
106
+ {
107
+ sol::optional<sol::error> result = lua.safe_script (R"(
108
+ result1_0 = get_table_exhaustive(expect1_0)
109
+ assert(result1_0 == 1)
110
+ result1_1 = get_table_exhaustive(expect1_1)
111
+ assert(result1_1 == FAILURE_CONSTANT)
112
+ )" );
113
+ REQUIRE_FALSE (result.has_value ());
114
+ }
115
+ {
116
+ sol::optional<sol::error> result = lua.safe_script (R"(
117
+ result2_0 = get_table_exhaustive(expect2_0)
118
+ assert(result2_0 == 2)
119
+ result2_1 = get_table_exhaustive(expect2_1)
120
+ assert(result2_1 == FAILURE_CONSTANT)
121
+ )" );
122
+ REQUIRE_FALSE (result.has_value ());
123
+ }
110
124
}
0 commit comments