mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 16:57:04 +08:00
fix ChaiScript#537
This commit is contained in:
parent
5ff3679811
commit
cf7821cb1e
@ -22,6 +22,14 @@ namespace chaiscript
|
||||
template<typename Class, typename ... Params >
|
||||
Proxy_Function build_constructor_(Class (*)(Params...))
|
||||
{
|
||||
if constexpr (!std::is_copy_constructible_v<Class>) {
|
||||
auto call = [](auto && ... param) {
|
||||
return std::make_shared<Class>(std::forward<decltype(param)>(param)...);
|
||||
};
|
||||
|
||||
return Proxy_Function(
|
||||
chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Proxy_Function_Callable_Impl<std::shared_ptr<Class> (Params...), decltype(call)>>(call));
|
||||
} else if constexpr (true) {
|
||||
auto call = [](auto && ... param){
|
||||
return Class(std::forward<decltype(param)>(param)...);
|
||||
};
|
||||
@ -31,6 +39,7 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// \brief Generates a constructor function for use with ChaiScript
|
||||
|
||||
@ -1417,7 +1417,45 @@ TEST_CASE("Throw an exception when trying to add same conversion twice")
|
||||
std::cout << "My_int type conversion 2\n";
|
||||
return my_int(x);
|
||||
})), chaiscript::exception::conversion_error);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Test if non copyable/movable types can be registered")
|
||||
{
|
||||
struct Noncopyable {
|
||||
Noncopyable() {str = "test";}
|
||||
Noncopyable(const Noncopyable&) = delete;
|
||||
Noncopyable& operator=(const Noncopyable&) = delete;
|
||||
|
||||
std::string str;
|
||||
};
|
||||
|
||||
struct Nonmovable {
|
||||
Nonmovable() {str = "test";}
|
||||
Nonmovable(Nonmovable&&) = delete;
|
||||
Nonmovable& operator=(Nonmovable&&) = delete;
|
||||
|
||||
std::string str;
|
||||
};
|
||||
|
||||
struct Nothing {
|
||||
Nothing() {str = "test";}
|
||||
|
||||
Nothing(Nothing&&) = delete;
|
||||
Nothing& operator=(Nothing&&) = delete;
|
||||
|
||||
Nothing(const Nothing&) = delete;
|
||||
Nothing& operator=(const Nothing&) = delete;
|
||||
|
||||
std::string str;
|
||||
};
|
||||
|
||||
chaiscript::ChaiScript chai;
|
||||
chai.add(chaiscript::user_type<Noncopyable>(), "Noncopyable");
|
||||
chai.add(chaiscript::constructor<Noncopyable()>(), "Noncopyable");
|
||||
|
||||
chai.add(chaiscript::user_type<Nonmovable>(), "Nonmovable");
|
||||
chai.add(chaiscript::constructor<Nonmovable()>(), "Nonmovable");
|
||||
|
||||
chai.add(chaiscript::user_type<Nothing>(), "Nothing");
|
||||
chai.add(chaiscript::constructor<Nothing()>(), "Nothing");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user