mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Ensures value semantics and proper destructor calls.
Fixes for tabs/spaces
This commit is contained in:
parent
f389c7fe36
commit
f21f9c9959
|
@ -376,7 +376,7 @@ struct pusher<function_sig_t<Sigs...>> {
|
||||||
template<typename Fx, typename T>
|
template<typename Fx, typename T>
|
||||||
static void set_reference_fx(std::false_type, lua_State* L, Fx&& fx, T&& obj) {
|
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;
|
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));
|
return set_fx<Fx>(L, std::move(sptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ struct pusher<function_sig_t<Sigs...>> {
|
||||||
|
|
||||||
template<typename Fx>
|
template<typename Fx>
|
||||||
static void set_fx(lua_State* L, std::unique_ptr<base_function> luafunc) {
|
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]);
|
const char* metatablename = std::addressof(metakey[0]);
|
||||||
base_function* target = luafunc.release();
|
base_function* target = luafunc.release();
|
||||||
void* userdata = reinterpret_cast<void*>(target);
|
void* userdata = reinterpret_cast<void*>(target);
|
||||||
|
|
|
@ -373,7 +373,8 @@ struct member_function : public base_function {
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
return_type operator()(Args&&... 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;
|
} fx;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "tuple.hpp"
|
#include "tuple.hpp"
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
|
@ -324,6 +325,35 @@ Unwrap<Arg> unwrapper(std::reference_wrapper<Arg> arg) {
|
||||||
return arg.get();
|
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
|
} // sol
|
||||||
|
|
||||||
#endif // SOL_TRAITS_HPP
|
#endif // SOL_TRAITS_HPP
|
||||||
|
|
Loading…
Reference in New Issue
Block a user