From 72da0b8d87a62fab1f7178081819aec2a0a768e8 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 24 May 2024 17:12:04 +0200 Subject: [PATCH] Fix build when std::string is a lone parameter The "any tuple-like" thing was nice but it was confusing when passing for example a std::string, which is a typedef to a tuple-like thing. Making a custom ConstructorParameters struct is more clear both to users and to the compiler. --- examples/math_vector/main.cpp | 5 +++-- include/wrenpp/detail/construct_foreign_class.hpp | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/math_vector/main.cpp b/examples/math_vector/main.cpp index 742f491..a99df27 100644 --- a/examples/math_vector/main.cpp +++ b/examples/math_vector/main.cpp @@ -108,6 +108,7 @@ System.print("vec_base_x modified by scripting: <%(vec_base_x.x), %(vec_base_x.y int main() { using wren::make_function_bindable; using wren::make_foreign_class; + using wren::ConstructorParameters; MyConf conf; wren::VM vm(&conf, nullptr); @@ -123,8 +124,8 @@ int main() { vm.class_manager() .add_class_maker("math_vector", "MathVector", make_foreign_class, double, //single value constructor - std::tuple, //x,y,z constructor - std::tuple<> //default constructor + ConstructorParameters, //x,y,z constructor + ConstructorParameters<> //default constructor >); vm.interpret("main", g_test_script); diff --git a/include/wrenpp/detail/construct_foreign_class.hpp b/include/wrenpp/detail/construct_foreign_class.hpp index 615a3be..58d1803 100644 --- a/include/wrenpp/detail/construct_foreign_class.hpp +++ b/include/wrenpp/detail/construct_foreign_class.hpp @@ -23,11 +23,12 @@ # include "guess_class_name.hpp" #endif #include -#include #include #include namespace wren { + template struct ConstructorParameters { }; + namespace detail { template inline void construct_single ( @@ -46,13 +47,13 @@ namespace wren { template struct ForeignClassHelper; - template class Pack, typename... PackArgs, typename... Args> - struct ForeignClassHelper, Args...> { + template + struct ForeignClassHelper, Args...> { static ConstructResult construct (VM& vm, int cardinality, void* memory) { using std::make_integer_sequence; //search by number of parameters. - //once we find a tuple-like parameter that contains the right + //once we find a ConstructorParameters that contains the right //number of types we invoke construct_single() with those types. constexpr int pack_size = static_cast(sizeof...(PackArgs)); if (pack_size == cardinality) {