Ensures value semantics and proper destructor calls.

Fixes for tabs/spaces
This commit is contained in:
ThePhD 2016-01-28 19:57:02 -05:00
parent f389c7fe36
commit f21f9c9959
7 changed files with 283 additions and 252 deletions

View File

@ -376,7 +376,7 @@ struct pusher<function_sig_t<Sigs...>> {
template<typename Fx, typename T>
static void set_reference_fx(std::false_type, lua_State* L, Fx&& fx, T&& obj) {
typedef typename std::remove_pointer<Decay<Fx>>::type clean_fx;
std::unique_ptr<base_function> sptr(new member_function<clean_fx, T>(std::forward<T>(obj), std::forward<Fx>(fx)));
std::unique_ptr<base_function> sptr(new member_function<clean_fx, Unqualified<T>>(std::forward<T>(obj), std::forward<Fx>(fx)));
return set_fx<Fx>(L, std::move(sptr));
}
@ -411,7 +411,7 @@ struct pusher<function_sig_t<Sigs...>> {
template<typename Fx>
static void set_fx(lua_State* L, std::unique_ptr<base_function> luafunc) {
auto&& metakey = usertype_traits<Unqualified<Fx>>::metatable;
const auto& metakey = usertype_traits<Unqualified<Fx>>::metatable;
const char* metatablename = std::addressof(metakey[0]);
base_function* target = luafunc.release();
void* userdata = reinterpret_cast<void*>(target);

View File

@ -373,7 +373,8 @@ struct member_function : public base_function {
template<typename... Args>
return_type operator()(Args&&... args) {
return (member.*invocation)(std::forward<Args>(args)...);
auto& mem = unwrapper(unref(member));
return (mem.*invocation)(std::forward<Args>(args)...);
}
} fx;

View File

@ -24,6 +24,7 @@
#include "tuple.hpp"
#include <type_traits>
#include <memory>
#include <functional>
namespace sol {
@ -324,6 +325,35 @@ Unwrap<Arg> unwrapper(std::reference_wrapper<Arg> arg) {
return arg.get();
}
template<typename T>
T& unref(T& item) {
return item;
}
template<typename T>
T& unref(T* item) {
return *item;
}
template<typename T>
T& unref(std::unique_ptr<T>& item) {
return *item;
}
template<typename T>
T& unref(std::shared_ptr<T>& item) {
return *item;
}
template<typename T>
T& unref(const std::unique_ptr<T>& item) {
return *item;
}
template<typename T>
T& unref(const std::shared_ptr<T>& item) {
return *item;
}
} // sol
#endif // SOL_TRAITS_HPP