Skip to content

Commit 5a4d7dc

Browse files
committed
pointers just wanna be included in the fun, man
1 parent 46a2b01 commit 5a4d7dc

File tree

6 files changed

+57
-15
lines changed

6 files changed

+57
-15
lines changed

include/sol/stack_core.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,18 @@ namespace sol {
530530
}
531531

532532
struct properties_enrollment_allowed {
533+
int& times_through;
533534
std::bitset<64>& properties;
534535
automagic_enrollments& enrollments;
535536

536-
properties_enrollment_allowed(std::bitset<64>& props, automagic_enrollments& enroll) : properties(props), enrollments(enroll) {
537+
properties_enrollment_allowed(int& times, std::bitset<64>& props, automagic_enrollments& enroll) : times_through(times), properties(props), enrollments(enroll) {
537538
}
538539

539540
bool operator()(meta_function mf) const {
540541
bool p = properties[static_cast<int>(mf)];
542+
if (times_through > 0) {
543+
return p;
544+
}
541545
switch (mf) {
542546
case meta_function::length:
543547
return enrollments.length_operator && !p;

include/sol/usertype_storage.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ namespace sol { namespace u_detail {
965965
// add intrinsics
966966
// this one is the actual meta-handling table,
967967
// the next one will be the one for
968-
968+
int for_each_backing_metatable_calls = 0;
969969
auto for_each_backing_metatable = [&](lua_State* L, submetatable_type smt, reference& fast_index_table) {
970970
// Pointer types, AKA "references" from C++
971971
const char* metakey = nullptr;
@@ -1039,8 +1039,8 @@ namespace sol { namespace u_detail {
10391039
stack::set_field<false, true>(L, detail::base_class_check_key(), reinterpret_cast<void*>(&detail::inheritance<T>::type_check), t.stack_index());
10401040
stack::set_field<false, true>(L, detail::base_class_cast_key(), reinterpret_cast<void*>(&detail::inheritance<T>::type_cast), t.stack_index());
10411041

1042-
auto prop_fx = detail::properties_enrollment_allowed(storage.properties, enrollments);
1043-
auto insert_fx = [&L, &t, &storage](meta_function mf, lua_CFunction reg) {
1042+
auto prop_fx = detail::properties_enrollment_allowed(for_each_backing_metatable_calls, storage.properties, enrollments);
1043+
auto insert_fx = [&L, &t, &storage, &smt](meta_function mf, lua_CFunction reg) {
10441044
stack::set_field<false, true>(L, mf, reg, t.stack_index());
10451045
storage.properties[static_cast<int>(mf)] = true;
10461046
};
@@ -1082,6 +1082,7 @@ namespace sol { namespace u_detail {
10821082
storage.is_using_new_index = true;
10831083
}
10841084

1085+
++for_each_backing_metatable_calls;
10851086
fast_index_table = reference(L, t);
10861087
t.pop();
10871088
};

single/include/sol/forward.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
// This file was generated with a script.
23-
// Generated 2019-05-27 05:35:30.258702 UTC
24-
// This header was generated with sol v3.0.2 (revision e814868)
23+
// Generated 2019-05-29 20:53:05.788092 UTC
24+
// This header was generated with sol v3.0.2 (revision 46a2b01)
2525
// https://github.com/ThePhD/sol2
2626

2727
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP

single/include/sol/sol.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
// This file was generated with a script.
23-
// Generated 2019-05-27 05:35:29.780976 UTC
24-
// This header was generated with sol v3.0.2 (revision e814868)
23+
// Generated 2019-05-29 20:53:04.799735 UTC
24+
// This header was generated with sol v3.0.2 (revision 46a2b01)
2525
// https://github.com/ThePhD/sol2
2626

2727
#ifndef SOL_SINGLE_INCLUDE_HPP
@@ -9682,14 +9682,18 @@ namespace sol {
96829682
}
96839683

96849684
struct properties_enrollment_allowed {
9685+
int& times_through;
96859686
std::bitset<64>& properties;
96869687
automagic_enrollments& enrollments;
96879688

9688-
properties_enrollment_allowed(std::bitset<64>& props, automagic_enrollments& enroll) : properties(props), enrollments(enroll) {
9689+
properties_enrollment_allowed(int& times, std::bitset<64>& props, automagic_enrollments& enroll) : times_through(times), properties(props), enrollments(enroll) {
96899690
}
96909691

96919692
bool operator()(meta_function mf) const {
96929693
bool p = properties[static_cast<int>(mf)];
9694+
if (times_through > 0) {
9695+
return p;
9696+
}
96939697
switch (mf) {
96949698
case meta_function::length:
96959699
return enrollments.length_operator && !p;
@@ -11686,8 +11690,7 @@ namespace sol { namespace stack {
1168611690
static decltype(auto) get(lua_State* L, int index, record& tracking) {
1168711691
using Tu = meta::unqualified_t<X>;
1168811692
static constexpr bool is_userdata_of_some_kind
11689-
= !std::is_reference_v<
11690-
X> && is_container_v<Tu> && std::is_default_constructible_v<Tu> && !is_lua_primitive_v<Tu> && !is_transparent_argument_v<Tu>;
11693+
= !std::is_reference_v<X> && is_container_v<Tu> && std::is_default_constructible_v<Tu> && !is_lua_primitive_v<Tu> && !is_transparent_argument_v<Tu>;
1169111694
if constexpr (is_userdata_of_some_kind) {
1169211695
if (type_of(L, index) == type::userdata) {
1169311696
return static_cast<Tu>(stack_detail::unchecked_unqualified_get<Tu>(L, index, tracking));
@@ -21676,7 +21679,7 @@ namespace sol { namespace u_detail {
2167621679
// add intrinsics
2167721680
// this one is the actual meta-handling table,
2167821681
// the next one will be the one for
21679-
21682+
int for_each_backing_metatable_calls = 0;
2168021683
auto for_each_backing_metatable = [&](lua_State* L, submetatable_type smt, reference& fast_index_table) {
2168121684
// Pointer types, AKA "references" from C++
2168221685
const char* metakey = nullptr;
@@ -21750,8 +21753,8 @@ namespace sol { namespace u_detail {
2175021753
stack::set_field<false, true>(L, detail::base_class_check_key(), reinterpret_cast<void*>(&detail::inheritance<T>::type_check), t.stack_index());
2175121754
stack::set_field<false, true>(L, detail::base_class_cast_key(), reinterpret_cast<void*>(&detail::inheritance<T>::type_cast), t.stack_index());
2175221755

21753-
auto prop_fx = detail::properties_enrollment_allowed(storage.properties, enrollments);
21754-
auto insert_fx = [&L, &t, &storage](meta_function mf, lua_CFunction reg) {
21756+
auto prop_fx = detail::properties_enrollment_allowed(for_each_backing_metatable_calls, storage.properties, enrollments);
21757+
auto insert_fx = [&L, &t, &storage, &smt](meta_function mf, lua_CFunction reg) {
2175521758
stack::set_field<false, true>(L, mf, reg, t.stack_index());
2175621759
storage.properties[static_cast<int>(mf)] = true;
2175721760
};
@@ -21793,6 +21796,7 @@ namespace sol { namespace u_detail {
2179321796
storage.is_using_new_index = true;
2179421797
}
2179521798

21799+
++for_each_backing_metatable_calls;
2179621800
fast_index_table = reference(L, t);
2179721801
t.pop();
2179821802
};

tests/runtime_tests/source/operators.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
#include <numeric>
3030
#include <iostream>
3131

32+
struct T {};
33+
3234
TEST_CASE("operators/default", "test that generic equality operators and all sorts of equality tests can be used") {
33-
struct T {};
3435
struct U {
3536
int a;
3637
U(int x = 20) : a(x) {
@@ -186,6 +187,31 @@ TEST_CASE("operators/default", "test that generic equality operators and all sor
186187
}
187188
}
188189

190+
TEST_CASE("operators/default with pointers", "test that default operations still work when working with reference (pointer) types") {
191+
sol::state lua;
192+
lua.open_libraries(sol::lib::base);
193+
194+
lua.new_usertype<T>("T");
195+
196+
T test;
197+
198+
lua["t1"] = &test;
199+
lua["t2"] = &test;
200+
lua["t3"] = std::unique_ptr<T, no_delete>(&test);
201+
lua["t4"] = std::unique_ptr<T, no_delete>(&test);
202+
203+
lua.script("ptr_test = t1 == t2");
204+
lua.script("ptr_unique_test = t1 == t3");
205+
lua.script("unique_test = t3 == t4");
206+
207+
bool ptr_test = lua["ptr_test"];
208+
bool ptr_unique_test = lua["ptr_unique_test"];
209+
bool unique_test = lua["unique_test"];
210+
REQUIRE(ptr_test);
211+
REQUIRE(ptr_unique_test);
212+
REQUIRE(unique_test);
213+
}
214+
189215
TEST_CASE("operators/call", "test call operator generation") {
190216
struct callable {
191217
int operator()(int a, std::string b) {

tests/runtime_tests/source/sol_test.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,11 @@ struct test_stack_guard {
6565
}
6666
};
6767

68+
struct no_delete {
69+
template <typename P>
70+
void operator()(P) const noexcept {
71+
72+
}
73+
};
74+
6875
#endif // SOL_TESTS_SOL_TEST_HPP

0 commit comments

Comments
 (0)