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.
This commit is contained in:
parent
ea19e35f85
commit
72da0b8d87
2 changed files with 8 additions and 6 deletions
|
@ -108,6 +108,7 @@ System.print("vec_base_x modified by scripting: <%(vec_base_x.x), %(vec_base_x.y
|
||||||
int main() {
|
int main() {
|
||||||
using wren::make_function_bindable;
|
using wren::make_function_bindable;
|
||||||
using wren::make_foreign_class;
|
using wren::make_foreign_class;
|
||||||
|
using wren::ConstructorParameters;
|
||||||
|
|
||||||
MyConf conf;
|
MyConf conf;
|
||||||
wren::VM vm(&conf, nullptr);
|
wren::VM vm(&conf, nullptr);
|
||||||
|
@ -123,8 +124,8 @@ int main() {
|
||||||
vm.class_manager()
|
vm.class_manager()
|
||||||
.add_class_maker("math_vector", "MathVector", make_foreign_class<Vector<double>,
|
.add_class_maker("math_vector", "MathVector", make_foreign_class<Vector<double>,
|
||||||
double, //single value constructor
|
double, //single value constructor
|
||||||
std::tuple<double, double, double>, //x,y,z constructor
|
ConstructorParameters<double, double, double>, //x,y,z constructor
|
||||||
std::tuple<> //default constructor
|
ConstructorParameters<> //default constructor
|
||||||
>);
|
>);
|
||||||
|
|
||||||
vm.interpret("main", g_test_script);
|
vm.interpret("main", g_test_script);
|
||||||
|
|
|
@ -23,11 +23,12 @@
|
||||||
# include "guess_class_name.hpp"
|
# include "guess_class_name.hpp"
|
||||||
#endif
|
#endif
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <tuple>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace wren {
|
namespace wren {
|
||||||
|
template <typename... Args> struct ConstructorParameters { };
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template <typename T, typename... Args, int... Indices>
|
template <typename T, typename... Args, int... Indices>
|
||||||
inline void construct_single (
|
inline void construct_single (
|
||||||
|
@ -46,13 +47,13 @@ namespace wren {
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
struct ForeignClassHelper;
|
struct ForeignClassHelper;
|
||||||
|
|
||||||
template <typename T, template <typename...> class Pack, typename... PackArgs, typename... Args>
|
template <typename T, typename... PackArgs, typename... Args>
|
||||||
struct ForeignClassHelper<T, Pack<PackArgs...>, Args...> {
|
struct ForeignClassHelper<T, ConstructorParameters<PackArgs...>, Args...> {
|
||||||
static ConstructResult construct (VM& vm, int cardinality, void* memory) {
|
static ConstructResult construct (VM& vm, int cardinality, void* memory) {
|
||||||
using std::make_integer_sequence;
|
using std::make_integer_sequence;
|
||||||
|
|
||||||
//search by number of parameters.
|
//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.
|
//number of types we invoke construct_single() with those types.
|
||||||
constexpr int pack_size = static_cast<int>(sizeof...(PackArgs));
|
constexpr int pack_size = static_cast<int>(sizeof...(PackArgs));
|
||||||
if (pack_size == cardinality) {
|
if (pack_size == cardinality) {
|
||||||
|
|
Loading…
Reference in a new issue