From af2136ba0066d90b65c04059d1c7b73ccfd0a386 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 26 Jun 2017 10:10:47 -0400 Subject: [PATCH] Closes #431 If only I had a test that took a unique_ptr as a second argument. RIP. --- single/sol/sol.hpp | 6 +++--- sol/stack_check.hpp | 2 +- test_functions.cpp | 7 ++++++- test_usertypes.cpp | 17 ++++++++++------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 3f0622cc..ad1296e9 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2017-06-24 14:16:16.927775 UTC -// This header was generated with sol v2.17.5 (revision 17271c8) +// Generated 2017-06-26 14:10:10.059447 UTC +// This header was generated with sol v2.17.5 (revision 13370e7) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -5707,7 +5707,7 @@ namespace sol { } int metatableindex = lua_gettop(L); if (stack_detail::check_metatable>(L, metatableindex)) { - void* memory = lua_touserdata(L, 1); + void* memory = lua_touserdata(L, index); T** pointerpointer = static_cast(memory); detail::unique_destructor& pdx = *static_cast(static_cast(pointerpointer + 1)); bool success = &detail::usertype_unique_alloc_destroy == pdx; diff --git a/sol/stack_check.hpp b/sol/stack_check.hpp index 936c2ece..570adbb6 100644 --- a/sol/stack_check.hpp +++ b/sol/stack_check.hpp @@ -430,7 +430,7 @@ namespace sol { } int metatableindex = lua_gettop(L); if (stack_detail::check_metatable>(L, metatableindex)) { - void* memory = lua_touserdata(L, 1); + void* memory = lua_touserdata(L, index); T** pointerpointer = static_cast(memory); detail::unique_destructor& pdx = *static_cast(static_cast(pointerpointer + 1)); bool success = &detail::usertype_unique_alloc_destroy == pdx; diff --git a/test_functions.cpp b/test_functions.cpp index 63acbbbc..e07a27fa 100644 --- a/test_functions.cpp +++ b/test_functions.cpp @@ -1149,6 +1149,9 @@ TEST_CASE("functions/unique-overloading", "make sure overloading can work with p auto print_up_test = [](std::unique_ptr& x) { REQUIRE(x->special_value == 21); }; + auto print_up_2_test = [](int, std::unique_ptr& x) { + REQUIRE(x->special_value == 21); + }; auto print_sp_test = [](std::shared_ptr& x) { REQUIRE(x->special_value == 44); }; @@ -1158,7 +1161,7 @@ TEST_CASE("functions/unique-overloading", "make sure overloading can work with p auto print_ref_test = [](test& x) { bool is_any = x.special_value == 17 || x.special_value == 21 - || x. special_value == 44; + || x.special_value == 44; REQUIRE(is_any); }; using f_t = void(test&); @@ -1175,6 +1178,7 @@ TEST_CASE("functions/unique-overloading", "make sure overloading can work with p std::ref(print_ptr_test) )); lua.set_function("h", std::ref(fptr)); + lua.set_function("i", std::move(print_up_2_test)); lua["v1"] = std::make_unique(21); lua["v2"] = std::make_shared(44); @@ -1191,6 +1195,7 @@ TEST_CASE("functions/unique-overloading", "make sure overloading can work with p lua.script("h(v2)"); lua.script("h(v3)"); lua.script("h(v4)"); + lua.script("i(v1)"); }()); }; // LuaJIT segfaults hard on some Linux machines diff --git a/test_usertypes.cpp b/test_usertypes.cpp index 0e687eb0..a211f111 100644 --- a/test_usertypes.cpp +++ b/test_usertypes.cpp @@ -1464,11 +1464,11 @@ TEST_CASE("usertype/unique_usertype-check", "make sure unique usertypes don't ge sol::function my_func = lua["my_func"]; REQUIRE_NOTHROW([&]{ - auto ent = std::make_shared(); - my_func(ent); - Entity ent2; - my_func(ent2); - my_func(std::make_shared()); + auto ent = std::make_shared(); + my_func(ent); + Entity ent2; + my_func(ent2); + my_func(std::make_shared()); }()); } @@ -1476,9 +1476,12 @@ TEST_CASE("usertype/abstract-base-class", "Ensure that abstract base classes and sol::state lua; lua.new_usertype("A", "a", &abstract_A::a); lua.new_usertype("B", sol::base_classes, sol::bases()); - lua.script(R"(local b = B.new() + REQUIRE_NOTHROW([&]() { + lua.script(R"( +local b = B.new() b:a() -)"); + )"); + }); } TEST_CASE("usertype/as_function", "Ensure that variables can be turned into functions by as_function") {