diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 31b16e05..be849c87 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-09-13 16:53:17.844066 UTC -// This header was generated with sol v2.12.4 (revision 22d5a70) +// Generated 2016-09-14 04:01:54.009414 UTC +// This header was generated with sol v2.14.0 (revision 46b1077) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -3092,18 +3092,18 @@ namespace sol { template struct function_arguments { - std::tuple params; + std::tuple arguments; template , function_arguments>> = meta::enabler> - function_arguments(Arg&& arg, Args&&... args) : params(std::forward(arg), std::forward(args)...) {} + function_arguments(Arg&& arg, Args&&... args) : arguments(std::forward(arg), std::forward(args)...) {} }; template , typename... Args> - function_arguments...> as_function(Args&&... args) { + auto as_function(Args&&... args) { return function_arguments...>(std::forward(args)...); } template , typename... Args> - function_arguments as_function_reference(Args&&... args) { + auto as_function_reference(Args&&... args) { return function_arguments(std::forward(args)...); } @@ -4861,9 +4861,9 @@ namespace sol { namespace sol { template struct overload_set { - std::tuple set; + std::tuple functions; template >> = meta::enabler> - overload_set (Arg&& arg, Args&&... args) : set(std::forward(arg), std::forward(args)...) {} + overload_set (Arg&& arg, Args&&... args) : functions(std::forward(arg), std::forward(args)...) {} overload_set(const overload_set&) = default; overload_set(overload_set&&) = default; overload_set& operator=(const overload_set&) = default; @@ -5506,9 +5506,11 @@ namespace sol { return std::unique_ptr(new T(std::forward(args)...)); } - template + template struct tagged { - List l; + T value; + template , tagged>> = meta::enabler> + tagged(Arg&& arg, Args&&... args) : value(std::forward(arg), std::forward(args)...) {} }; } // detail @@ -5528,9 +5530,9 @@ namespace sol { template struct constructor_wrapper { - std::tuple set; - template - constructor_wrapper(Args&&... args) : set(std::forward(args)...) {} + std::tuple functions; + template , constructor_wrapper>> = meta::enabler> + constructor_wrapper(Arg&& arg, Args&&... args) : functions(std::forward(arg), std::forward(args)...) {} }; template @@ -5540,9 +5542,9 @@ namespace sol { template struct factory_wrapper { - std::tuple set; - template - factory_wrapper(Args&&... args) : set(std::forward(args)...) {} + std::tuple functions; + template , factory_wrapper>> = meta::enabler> + factory_wrapper(Arg&& arg, Args&&... args) : functions(std::forward(arg), std::forward(args)...) {} }; template @@ -7531,7 +7533,7 @@ namespace sol { T* obj = reinterpret_cast(pointerpointer + 1); referencepointer = obj; - auto& func = std::get(f.set); + auto& func = std::get(f.functions); stack::call_into_lua(r, a, L, boost + start, func, detail::implicit_wrapper(obj)); userdataref.push(); @@ -7584,7 +7586,7 @@ namespace sol { struct on_match { template int operator()(types, index_value, types, types, lua_State* L, int, int, F& fx) { - auto& f = std::get(fx.set); + auto& f = std::get(fx.functions); return lua_call_wrapper{}.call(L, f); } }; @@ -7601,7 +7603,7 @@ namespace sol { struct on_match { template int operator()(types, index_value, types, types, lua_State* L, int, int, F& fx) { - auto& f = std::get(fx.set); + auto& f = std::get(fx.functions); return lua_call_wrapper{}.call(L, f); } }; @@ -7679,7 +7681,7 @@ namespace sol { struct lua_call_wrapper, is_index, is_variable, checked, boost, C> { template static int call(lua_State* L, F&& f) { - return lua_call_wrapper, is_index, is_variable, stack::stack_detail::default_check_arguments, boost>{}.call(L, std::get<0>(f.params)); + return lua_call_wrapper, is_index, is_variable, stack::stack_detail::default_check_arguments, boost>{}.call(L, std::get<0>(f.arguments)); } }; @@ -8304,7 +8306,7 @@ namespace sol { struct pusher> { template static int push_func(std::index_sequence, lua_State* L, FP&& fp) { - return stack::push(L, detail::forward_get(fp.params)...); + return stack::push(L, detail::forward_get(fp.arguments)...); } static int push(lua_State* L, const function_arguments& fp) { @@ -8343,13 +8345,13 @@ namespace sol { struct pusher> { static int push(lua_State* L, overload_set&& set) { typedef function_detail::overloaded_function F; - pusher>{}.set_fx(L, std::move(set.set)); + pusher>{}.set_fx(L, std::move(set.functions)); return 1; } static int push(lua_State* L, const overload_set& set) { typedef function_detail::overloaded_function F; - pusher>{}.set_fx(L, set.set); + pusher>{}.set_fx(L, set.functions); return 1; } }; @@ -8409,6 +8411,21 @@ namespace sol { } }; + template + struct pusher> { + static int push(lua_State* L, const factory_wrapper& fw) { + typedef function_detail::overloaded_function F; + pusher>{}.set_fx(L, fw.functions); + return 1; + } + + static int push(lua_State* L, factory_wrapper&& fw) { + typedef function_detail::overloaded_function F; + pusher>{}.set_fx(L, std::move(fw.functions)); + return 1; + } + }; + template struct pusher>> { static int push(lua_State* L, detail::tagged>) { @@ -8419,9 +8436,10 @@ namespace sol { template struct pusher>> { - static int push(lua_State* L, constructor_wrapper c) { + template + static int push(lua_State* L, C&& c) { lua_CFunction cf = call_detail::call_user>; - int closures = stack::push>(L, std::move(c)); + int closures = stack::push>>(L, std::forward(c)); return stack::push(L, c_closure(cf, closures)); } }; @@ -10088,6 +10106,10 @@ namespace sol { template >> = meta::enabler> void add_function(lua_State* L, N&& n, F&& f) { + if (std::is_same, call_construction>::value) { + callconstructfunc = make_object(L, std::forward(f)); + return; + } registrations.emplace(usertype_detail::make_string(std::forward(n)), make_object(L, std::forward(f))); } @@ -10105,17 +10127,22 @@ namespace sol { template void add(lua_State* L, N&& n, constructor_wrapper c) { - registrations.emplace(usertype_detail::make_string(std::forward(n)), make_object(L, detail::tagged>{std::move(c)})); + object o(L, in_place>>, std::move(c)); + if (std::is_same, call_construction>::value) { + callconstructfunc = std::move(o); + return; + } + registrations.emplace(usertype_detail::make_string(std::forward(n)), std::move(o)); } template void add(lua_State* L, N&& n, constructor_list c) { - registrations.emplace(usertype_detail::make_string(std::forward(n)), make_object(L, detail::tagged>{std::move(c)})); - } - - template - void add(lua_State* L, call_construction, F&& f) { - callconstructfunc = make_object(L, std::forward(f)); + object o(L, in_place>>, std::move(c)); + if (std::is_same, call_construction>::value) { + callconstructfunc = std::move(o); + return; + } + registrations.emplace(usertype_detail::make_string(std::forward(n)), std::move(o)); } template diff --git a/sol/call.hpp b/sol/call.hpp index d2f2e90e..0abeeefa 100644 --- a/sol/call.hpp +++ b/sol/call.hpp @@ -383,7 +383,7 @@ namespace sol { T* obj = reinterpret_cast(pointerpointer + 1); referencepointer = obj; - auto& func = std::get(f.set); + auto& func = std::get(f.functions); stack::call_into_lua(r, a, L, boost + start, func, detail::implicit_wrapper(obj)); userdataref.push(); @@ -436,7 +436,7 @@ namespace sol { struct on_match { template int operator()(types, index_value, types, types, lua_State* L, int, int, F& fx) { - auto& f = std::get(fx.set); + auto& f = std::get(fx.functions); return lua_call_wrapper{}.call(L, f); } }; @@ -453,7 +453,7 @@ namespace sol { struct on_match { template int operator()(types, index_value, types, types, lua_State* L, int, int, F& fx) { - auto& f = std::get(fx.set); + auto& f = std::get(fx.functions); return lua_call_wrapper{}.call(L, f); } }; @@ -531,7 +531,7 @@ namespace sol { struct lua_call_wrapper, is_index, is_variable, checked, boost, C> { template static int call(lua_State* L, F&& f) { - return lua_call_wrapper, is_index, is_variable, stack::stack_detail::default_check_arguments, boost>{}.call(L, std::get<0>(f.params)); + return lua_call_wrapper, is_index, is_variable, stack::stack_detail::default_check_arguments, boost>{}.call(L, std::get<0>(f.arguments)); } }; diff --git a/sol/function_types.hpp b/sol/function_types.hpp index 4dedfaba..a2eba3ec 100644 --- a/sol/function_types.hpp +++ b/sol/function_types.hpp @@ -181,7 +181,7 @@ namespace sol { struct pusher> { template static int push_func(std::index_sequence, lua_State* L, FP&& fp) { - return stack::push(L, detail::forward_get(fp.params)...); + return stack::push(L, detail::forward_get(fp.arguments)...); } static int push(lua_State* L, const function_arguments& fp) { @@ -220,13 +220,13 @@ namespace sol { struct pusher> { static int push(lua_State* L, overload_set&& set) { typedef function_detail::overloaded_function F; - pusher>{}.set_fx(L, std::move(set.set)); + pusher>{}.set_fx(L, std::move(set.functions)); return 1; } static int push(lua_State* L, const overload_set& set) { typedef function_detail::overloaded_function F; - pusher>{}.set_fx(L, set.set); + pusher>{}.set_fx(L, set.functions); return 1; } }; @@ -286,6 +286,21 @@ namespace sol { } }; + template + struct pusher> { + static int push(lua_State* L, const factory_wrapper& fw) { + typedef function_detail::overloaded_function F; + pusher>{}.set_fx(L, fw.functions); + return 1; + } + + static int push(lua_State* L, factory_wrapper&& fw) { + typedef function_detail::overloaded_function F; + pusher>{}.set_fx(L, std::move(fw.functions)); + return 1; + } + }; + template struct pusher>> { static int push(lua_State* L, detail::tagged>) { @@ -296,9 +311,10 @@ namespace sol { template struct pusher>> { - static int push(lua_State* L, constructor_wrapper c) { + template + static int push(lua_State* L, C&& c) { lua_CFunction cf = call_detail::call_user>; - int closures = stack::push>(L, std::move(c)); + int closures = stack::push>>(L, std::forward(c)); return stack::push(L, c_closure(cf, closures)); } }; diff --git a/sol/overload.hpp b/sol/overload.hpp index 54f723da..316a3322 100644 --- a/sol/overload.hpp +++ b/sol/overload.hpp @@ -27,9 +27,9 @@ namespace sol { template struct overload_set { - std::tuple set; + std::tuple functions; template >> = meta::enabler> - overload_set (Arg&& arg, Args&&... args) : set(std::forward(arg), std::forward(args)...) {} + overload_set (Arg&& arg, Args&&... args) : functions(std::forward(arg), std::forward(args)...) {} overload_set(const overload_set&) = default; overload_set(overload_set&&) = default; overload_set& operator=(const overload_set&) = default; diff --git a/sol/raii.hpp b/sol/raii.hpp index 1282e4b1..c7b20a69 100644 --- a/sol/raii.hpp +++ b/sol/raii.hpp @@ -65,9 +65,11 @@ namespace sol { return std::unique_ptr(new T(std::forward(args)...)); } - template + template struct tagged { - List l; + T value; + template , tagged>> = meta::enabler> + tagged(Arg&& arg, Args&&... args) : value(std::forward(arg), std::forward(args)...) {} }; } // detail @@ -87,9 +89,9 @@ namespace sol { template struct constructor_wrapper { - std::tuple set; - template - constructor_wrapper(Args&&... args) : set(std::forward(args)...) {} + std::tuple functions; + template , constructor_wrapper>> = meta::enabler> + constructor_wrapper(Arg&& arg, Args&&... args) : functions(std::forward(arg), std::forward(args)...) {} }; template @@ -99,9 +101,9 @@ namespace sol { template struct factory_wrapper { - std::tuple set; - template - factory_wrapper(Args&&... args) : set(std::forward(args)...) {} + std::tuple functions; + template , factory_wrapper>> = meta::enabler> + factory_wrapper(Arg&& arg, Args&&... args) : functions(std::forward(arg), std::forward(args)...) {} }; template diff --git a/sol/simple_usertype_metatable.hpp b/sol/simple_usertype_metatable.hpp index d42a81db..44d3bef6 100644 --- a/sol/simple_usertype_metatable.hpp +++ b/sol/simple_usertype_metatable.hpp @@ -153,6 +153,10 @@ namespace sol { template >> = meta::enabler> void add_function(lua_State* L, N&& n, F&& f) { + if (std::is_same, call_construction>::value) { + callconstructfunc = make_object(L, std::forward(f)); + return; + } registrations.emplace(usertype_detail::make_string(std::forward(n)), make_object(L, std::forward(f))); } @@ -170,17 +174,22 @@ namespace sol { template void add(lua_State* L, N&& n, constructor_wrapper c) { - registrations.emplace(usertype_detail::make_string(std::forward(n)), make_object(L, detail::tagged>{std::move(c)})); + object o(L, in_place>>, std::move(c)); + if (std::is_same, call_construction>::value) { + callconstructfunc = std::move(o); + return; + } + registrations.emplace(usertype_detail::make_string(std::forward(n)), std::move(o)); } template void add(lua_State* L, N&& n, constructor_list c) { - registrations.emplace(usertype_detail::make_string(std::forward(n)), make_object(L, detail::tagged>{std::move(c)})); - } - - template - void add(lua_State* L, call_construction, F&& f) { - callconstructfunc = make_object(L, std::forward(f)); + object o(L, in_place>>, std::move(c)); + if (std::is_same, call_construction>::value) { + callconstructfunc = std::move(o); + return; + } + registrations.emplace(usertype_detail::make_string(std::forward(n)), std::move(o)); } template diff --git a/sol/types.hpp b/sol/types.hpp index a0cf548b..d9ce88ae 100644 --- a/sol/types.hpp +++ b/sol/types.hpp @@ -261,18 +261,18 @@ namespace sol { template struct function_arguments { - std::tuple params; + std::tuple arguments; template , function_arguments>> = meta::enabler> - function_arguments(Arg&& arg, Args&&... args) : params(std::forward(arg), std::forward(args)...) {} + function_arguments(Arg&& arg, Args&&... args) : arguments(std::forward(arg), std::forward(args)...) {} }; template , typename... Args> - function_arguments...> as_function(Args&&... args) { + auto as_function(Args&&... args) { return function_arguments...>(std::forward(args)...); } template , typename... Args> - function_arguments as_function_reference(Args&&... args) { + auto as_function_reference(Args&&... args) { return function_arguments(std::forward(args)...); } diff --git a/test_simple_usertypes.cpp b/test_simple_usertypes.cpp index 0e13d96a..ffef869d 100644 --- a/test_simple_usertypes.cpp +++ b/test_simple_usertypes.cpp @@ -8,7 +8,7 @@ #include #include -TEST_CASE("usertypes/simple-usertypes", "Ensure that simple usertypes properly work here") { +TEST_CASE("usertype/simple-usertypes", "Ensure that simple usertypes properly work here") { struct marker { bool value = false; }; @@ -87,7 +87,7 @@ TEST_CASE("usertypes/simple-usertypes", "Ensure that simple usertypes properly w REQUIRE(z == 29); } -TEST_CASE("usertypes/simple-usertypes-constructors", "Ensure that calls with specific arguments work") { +TEST_CASE("usertype/simple-usertypes-constructors", "Ensure that calls with specific arguments work") { struct marker { bool value = false; }; @@ -211,7 +211,7 @@ TEST_CASE("usertype/simple-shared-ptr-regression", "simple usertype metatables s REQUIRE(destroyed == 1); } -TEST_CASE("usertypes/simple-vars", "simple usertype vars can bind various values (no ref)") { +TEST_CASE("usertype/simple-vars", "simple usertype vars can bind various values (no ref)") { int muh_variable = 10; int through_variable = 25; @@ -239,7 +239,7 @@ g2 = test.global2 REQUIRE(g2 == 25); } -TEST_CASE("simple_usertypes/variable-control", "test to see if usertypes respond to inheritance and variable controls") { +TEST_CASE("usertypes/simple-variable-control", "test to see if usertypes respond to inheritance and variable controls") { class A { public: virtual void a() { throw std::runtime_error("entered base pure virtual implementation"); }; @@ -311,3 +311,59 @@ TEST_CASE("simple_usertypes/variable-control", "test to see if usertypes respond lua.script("print(sw.b)assert(sw.b == 25)"); lua.script("print(sw.pb)assert(sw.pb == 27)"); } + +TEST_CASE("usertype/simple-factory-constructor-overload-usage", "simple usertypes should probably invoke types") { + class A { + public: + virtual void a() { throw std::runtime_error("entered base pure virtual implementation"); }; + }; + + class B : public A { + public: + int bvar = 24; + virtual void a() override { } + void f() {} + }; + + sol::state lua; + lua.open_libraries(); + sol::constructors, sol::types> c; + lua.new_simple_usertype("B", + sol::call_constructor, c, + "new", sol::factories([]() { return B(); }), + "new2", sol::initializers([](B& mem) { new(&mem)B(); }, [](B& mem, int v) { new(&mem)B(); mem.bvar = v; }), + "f", sol::as_function(&B::bvar), + "g", sol::overload([](B&) { return 2; }, [](B&, int v) { return v; }) + ); + + lua.script("b = B()"); + lua.script("b2 = B.new()"); + lua.script("b3 = B.new2()"); + lua.script("b4 = B.new2(11)"); + + lua.script("x = b:f()"); + lua.script("x2 = b2:f()"); + lua.script("x3 = b3:f()"); + lua.script("x4 = b4:f()"); + int x = lua["x"]; + int x2 = lua["x2"]; + int x3 = lua["x3"]; + int x4 = lua["x4"]; + REQUIRE(x == 24); + REQUIRE(x2 == 24); + REQUIRE(x3 == 24); + REQUIRE(x4 == 11); + + lua.script("y = b:g()"); + lua.script("y2 = b2:g(3)"); + lua.script("y3 = b3:g()"); + lua.script("y4 = b4:g(3)"); + int y = lua["y"]; + int y2 = lua["y2"]; + int y3 = lua["y3"]; + int y4 = lua["y4"]; + REQUIRE(y == 2); + REQUIRE(y2 == 3); + REQUIRE(y3 == 2); + REQUIRE(y4 == 3); +}