mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
make sure proxies can be properly set to one another
This commit is contained in:
parent
c6d1ec8d68
commit
81ffb3f334
@ -63,12 +63,12 @@ namespace sol {
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename U, meta::enable<meta::is_callable<meta::unwrap_unqualified_t<U>>> = meta::enabler>
|
||||
template<typename U, meta::enable<meta::neg<is_lua_reference<meta::unwrap_unqualified_t<U>>>, meta::is_callable<meta::unwrap_unqualified_t<U>>> = meta::enabler>
|
||||
proxy& operator=(U&& other) {
|
||||
return set_function(std::forward<U>(other));
|
||||
}
|
||||
|
||||
template<typename U, meta::disable<meta::is_callable<meta::unwrap_unqualified_t<U>>> = meta::enabler>
|
||||
template<typename U, meta::disable<meta::neg<is_lua_reference<meta::unwrap_unqualified_t<U>>>, meta::is_callable<meta::unwrap_unqualified_t<U>>> = meta::enabler>
|
||||
proxy& operator=(U&& other) {
|
||||
return set(std::forward<U>(other));
|
||||
}
|
||||
|
@ -444,6 +444,8 @@ namespace sol {
|
||||
|
||||
class reference;
|
||||
class stack_reference;
|
||||
template <typename Table, typename Key>
|
||||
struct proxy;
|
||||
template<typename T>
|
||||
class usertype;
|
||||
template <bool, typename T>
|
||||
@ -662,6 +664,13 @@ namespace sol {
|
||||
|| meta::is_specialization_of<std::pair, meta::unqualified_t<T>>::value
|
||||
> { };
|
||||
|
||||
template <typename T>
|
||||
struct is_lua_reference : std::integral_constant<bool,
|
||||
std::is_base_of<reference, meta::unqualified_t<T>>::value
|
||||
|| std::is_base_of<stack_reference, meta::unqualified_t<T>>::value
|
||||
|| meta::is_specialization_of<proxy, meta::unqualified_t<T>>::value
|
||||
> { };
|
||||
|
||||
template <typename T>
|
||||
struct is_lua_primitive<T*> : std::true_type {};
|
||||
template <typename T>
|
||||
|
15
tests.cpp
15
tests.cpp
@ -648,3 +648,18 @@ TEST_CASE("pusher/constness", "Make sure more types can handle being const and j
|
||||
int x = foo.f()();
|
||||
REQUIRE(x == 20);
|
||||
}
|
||||
|
||||
TEST_CASE("proxy/proper-pushing", "allow proxies to reference other proxies and be serialized as the proxy itself and not a function or something") {
|
||||
sol::state lua;
|
||||
lua.open_libraries(sol::lib::base, sol::lib::io);
|
||||
|
||||
class T {};
|
||||
lua.new_usertype<T>("T");
|
||||
|
||||
T t;
|
||||
lua["t1"] = &t;
|
||||
lua["t2"] = lua["t1"];
|
||||
lua.script("b = t1 == t2");
|
||||
bool b = lua["b"];
|
||||
REQUIRE(b);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user