From 9c67e9310e9aa37a5d836c9fe6da527f1dfb3a4c Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sun, 7 Aug 2016 12:58:05 -0400 Subject: [PATCH] One more test --- test_usertypes.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test_usertypes.cpp b/test_usertypes.cpp index 86c64eeb..d90129bd 100644 --- a/test_usertypes.cpp +++ b/test_usertypes.cpp @@ -933,6 +933,38 @@ t = thing(256) REQUIRE(y.v == 256); } +TEST_CASE("usertype/call_constructor_2", "prevent metatable regression") { + class class01 { + public: + int x = 57; + class01() {} + }; + + class class02 { + public: + int x = 50; + class02() {} + class02(const class01& other) : x(other.x) {} + }; + + sol::state lua; + + lua.new_usertype("class01", + sol::call_constructor, sol::constructors, sol::types>() + ); + + lua.new_usertype("class02", + sol::call_constructor, sol::constructors, sol::types, sol::types>() + ); + + REQUIRE_NOTHROW(lua.script(R"( +x = class01() +y = class02(x) +)")); + class02& y = lua["y"]; + REQUIRE(y.x == 57); +} + TEST_CASE("usertype/blank_constructor", "make sure lua types cannot be constructed if a blank / empty constructor is provided") { sol::state lua; lua.open_libraries(sol::lib::base);