From 2640f670b6e82b65fde2521b8c525a4ccf12349c Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sun, 21 Aug 2016 22:17:19 -0400 Subject: [PATCH] better tests, wee --- single/sol/sol.hpp | 6 +++--- test_usertypes.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 71a2abfe..6d1ec7c4 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 2016-08-21 23:25:04.369074 UTC -// This header was generated with sol v2.11.6 (revision 6243cbe) +// Generated 2016-08-22 02:15:33.510154 UTC +// This header was generated with sol v2.11.5 (revision 56ed859) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -3968,7 +3968,7 @@ namespace sol { std::is_lvalue_reference, meta::neg>, meta::neg>>, - meta::neg> + meta::neg>> > use_reference_tag; return pusher>>{}.push(L, std::forward(t), std::forward(args)...); } diff --git a/test_usertypes.cpp b/test_usertypes.cpp index 549d94b3..9b980f76 100644 --- a/test_usertypes.cpp +++ b/test_usertypes.cpp @@ -1406,3 +1406,36 @@ TEST_CASE("usertype/inheritance", "test that metatables are properly inherited") REQUIRE(b == 10); REQUIRE(a == 5); } + +TEST_CASE("usertype/unique_usertype-check", "make sure unique usertypes don't get pushed as references with function calls and the like") { + class Entity { + public: + std::string GetName() { + return "Charmander"; + } + }; + + sol::state lua; + lua.open_libraries(sol::lib::base, sol::lib::math, sol::lib::string, sol::lib::io); + + lua.new_usertype("Entity", + "new", sol::no_constructor, + "get_name", &Entity::GetName + ); + + lua.script(R"( + function my_func(entity) + print("INSIDE LUA") + print(entity:get_name()) + end +)"); + + 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()); + }); +}